On Tue, Mar 17, 2026 at 05:11:42PM +0100, Jakub Jelinek wrote:
> The following patch adds a plugin (sorry, to check-g++ testsuite rather
> than libstdc++ testsuite because in plugin.exp we have all the needed
> infrastructure.

Here is a new version of the patch.  It now adds automatic whitelisting
(basically, any identifier (except for namespace identifiers, sorry) it sees 
inside
of std namespace and nested namespaces in it (excluding non-inline
namespaces with _ prefixed names) during the namespace and class and
also enumerators walk are whitelisted, and non-uglified name diagnostics
is deferred until end of TU at which point were report the non-whitelisted
ones one way and whitelisted ones another way which doesn't fail the
testcase).  And it does diagnose badnames and non-uglified names of
functions/classes etc. even in the implementation non-inline namespaces
like std::__gnu_cxx etc.

With the patch Jonathan posted, the results are (if you see something that
looks like a bug in the plugin, please let me know including details why and
I'll try to fix it):
libstdc++-v3/include/bits/atomic_base.h:1137:7: note: non-uglified name 
'is_lock_free'
libstdc++-v3/include/bits/atomic_base.h:1145:7: note: non-uglified name 'store'
libstdc++-v3/include/bits/atomic_base.h:1152:7: note: non-uglified name 'load'
libstdc++-v3/include/bits/atomic_base.h:1173:7: note: non-uglified name 
'compare_exchange_weak'
libstdc++-v3/include/bits/atomic_base.h:1183:7: note: non-uglified name 
'compare_exchange_strong'
libstdc++-v3/include/bits/atomic_base.h:1220:7: note: non-uglified name 
'fetch_add'
libstdc++-v3/include/bits/atomic_base.h:1225:7: note: non-uglified name 
'fetch_sub'
libstdc++-v3/include/bits/atomic_base.h:1230:7: note: non-uglified name 
'fetch_and'
libstdc++-v3/include/bits/atomic_base.h:1235:7: note: non-uglified name 
'fetch_or'
libstdc++-v3/include/bits/atomic_base.h:1240:7: note: non-uglified name 
'fetch_xor'
libstdc++-v3/include/bits/basic_string.h:3874:45: note: non-uglified name 
'allocator_type'
libstdc++-v3/include/bits/deque.tcc:1356:47: note: non-uglified name 
'difference_type'
libstdc++-v3/include/bits/hashtable_policy.h:605:5: note: non-uglified name 
'max_load_factor'
libstdc++-v3/include/bits/hashtable_policy.h:682:5: note: non-uglified name 
'max_load_factor'
libstdc++-v3/include/bits/streambuf_iterator.h:441:60: note: non-uglified name 
'traits_type'
libstdc++-v3/include/bits/streambuf_iterator.h:442:60: note: non-uglified name 
'streambuf_type'
libstdc++-v3/include/bits/streambuf_iterator.h:443:60: note: non-uglified name 
'int_type'
libstdc++-v3/include/bits/streambuf_iterator.h:488:60: note: non-uglified name 
'traits_type'
libstdc++-v3/include/bits/streambuf_iterator.h:489:60: note: non-uglified name 
'streambuf_type'
libstdc++-v3/include/bits/streambuf_iterator.h:490:60: note: non-uglified name 
'int_type'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:145:34:
 note: non-uglified name 'n'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:151:25:
 note: non-uglified name 'other'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:157:35:
 note: non-uglified name 'n'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:159:28:
 note: non-uglified name 'p_upper'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:170:36:
 note: non-uglified name 'n'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:172:22:
 note: non-uglified name 'p_lower'
libstdc++-v3/include/ext/throw_allocator.h:116:22: note: non-uglified name 'l'
libstdc++-v3/include/ext/throw_allocator.h:126:18: note: non-uglified name 
'entry'
libstdc++-v3/include/ext/throw_allocator.h:134:49: note: non-uglified name 
'inserted'
libstdc++-v3/include/ext/throw_allocator.h:159:12: note: non-uglified name 
'inserted'
libstdc++-v3/include/ext/throw_allocator.h:178:32: note: non-uglified name 
'found'
libstdc++-v3/include/ext/throw_allocator.h:201:18: note: non-uglified name 
'label'
libstdc++-v3/include/ext/throw_allocator.h:203:19: note: non-uglified name 
'found'
libstdc++-v3/include/ext/throw_allocator.h:240:19: note: non-uglified name 
'found'
libstdc++-v3/include/ext/throw_allocator.h:275:12: note: non-uglified name 
'found'
libstdc++-v3/include/ext/throw_allocator.h:288:30: note: non-uglified name 
'label'
libstdc++-v3/include/ext/throw_allocator.h:292:19: note: non-uglified name 
'found'
libstdc++-v3/include/ext/throw_allocator.h:318:32: note: non-uglified name 's'
libstdc++-v3/include/ext/throw_allocator.h:324:12: note: non-uglified name 'buf'
libstdc++-v3/include/ext/throw_allocator.h:325:18: note: non-uglified name 'tab'
libstdc++-v3/include/ext/throw_allocator.h:327:21: note: non-uglified name 'l'
libstdc++-v3/include/ext/throw_allocator.h:344:32: note: non-uglified name 's'
libstdc++-v3/include/ext/throw_allocator.h:350:12: note: non-uglified name 'buf'
libstdc++-v3/include/ext/throw_allocator.h:351:18: note: non-uglified name 'tab'
libstdc++-v3/include/ext/throw_allocator.h:353:21: note: non-uglified name 'l'
libstdc++-v3/include/ext/throw_allocator.h:389:28: note: non-uglified name 'os'
libstdc++-v3/include/ext/throw_allocator.h:392:27: note: non-uglified name 
'base_type'
libstdc++-v3/include/ext/throw_allocator.h:574:31: note: non-uglified name 
'distribution'
libstdc++-v3/include/ext/throw_allocator.h:575:19: note: non-uglified name 
'generator'
libstdc++-v3/include/ext/throw_allocator.h:578:75: note: non-uglified name 
'gen_t'
libstdc++-v3/include/ext/throw_allocator.h:579:25: note: non-uglified name 
'distribution'
libstdc++-v3/include/ext/throw_allocator.h:580:20: note: non-uglified name 
'generator'
libstdc++-v3/include/ext/throw_allocator.h:587:14: note: non-uglified name 
'random'
libstdc++-v3/include/ext/throw_allocator.h:593:16: note: non-uglified name 'buf'
libstdc++-v3/include/mdspan:3385:10: note: non-uglified name 'submdspan_mapping'
libstdc++-v3/include/ranges:9488:15: note: non-uglified name 'element_type'
libstdc++-v3/include/tr1/hashtable_policy.h:363:25: note: non-uglified name 
'first_argument_type'
libstdc++-v3/include/tr1/hashtable_policy.h:364:25: note: non-uglified name 
'second_argument_type'
libstdc++-v3/include/tr1/hashtable_policy.h:387:5: note: non-uglified name 
'max_load_factor'
libstdc++-v3/include/tr1/tuple:426:21: note: non-uglified name 'ignore'
and the whitelisted ones (those are just meant FYI by the test, in case one
would want to change any of those):
libstdc++-v3/libsupc++/compare:56:11: note: non-uglified whitelisted name 'type'
libstdc++-v3/libsupc++/compare:60:23: note: non-uglified whitelisted name 'less'
libstdc++-v3/libsupc++/compare:60:34: note: non-uglified whitelisted name 
'greater'
libstdc++-v3/libsupc++/compare:60:7: note: non-uglified whitelisted name 
'equivalent'
libstdc++-v3/libsupc++/compare:621:10: note: non-uglified whitelisted name 
'strong_order'
libstdc++-v3/libsupc++/compare:62:7: note: non-uglified whitelisted name 
'unordered'
libstdc++-v3/libsupc++/compare:630:10: note: non-uglified whitelisted name 
'weak_order'
libstdc++-v3/libsupc++/compare:639:10: note: non-uglified whitelisted name 
'partial_order'
libstdc++-v3/libsupc++/compare:750:13: note: non-uglified whitelisted name 
'int64_t'
libstdc++-v3/libsupc++/compare:751:13: note: non-uglified whitelisted name 
'int32_t'
libstdc++-v3/libsupc++/compare:752:13: note: non-uglified whitelisted name 
'int16_t'
libstdc++-v3/libsupc++/compare:753:13: note: non-uglified whitelisted name 
'uint64_t'
libstdc++-v3/libsupc++/compare:754:13: note: non-uglified whitelisted name 
'uint16_t'
libstdc++-v3/include/bits/alloc_traits.h:922:22: note: non-uglified whitelisted 
name 'swap'
libstdc++-v3/include/bits/atomic_base.h:1162:7: note: non-uglified whitelisted 
name 'exchange'
libstdc++-v3/include/bits/atomic_base.h:1194:7: note: non-uglified whitelisted 
name 'wait'
libstdc++-v3/include/bits/atomic_base.h:1205:7: note: non-uglified whitelisted 
name 'notify_one'
libstdc++-v3/include/bits/atomic_base.h:1212:7: note: non-uglified whitelisted 
name 'notify_all'
libstdc++-v3/include/bits/chrono.h:412:7: note: non-uglified whitelisted name 
'ceil'
libstdc++-v3/include/bits/chrono.h:490:9: note: non-uglified whitelisted name 
'ceil'
libstdc++-v3/include/bits/chrono_io.h:4259:8: note: non-uglified whitelisted 
name 'from_stream'
libstdc++-v3/include/bits/deque.tcc:1356:47: note: non-uglified whitelisted 
name 'difference_type'
libstdc++-v3/include/bits/exception_ptr.h:105:11: note: non-uglified 
whitelisted name 'exception_ptr'
libstdc++-v3/include/bits/exception_ptr.h:106:5: note: non-uglified whitelisted 
name 'exception_ptr'
libstdc++-v3/include/bits/exception_ptr.h:136:19: note: non-uglified 
whitelisted name 'rethrow_exception'
libstdc++-v3/include/bits/exception_ptr.h:279:5: note: non-uglified whitelisted 
name 'swap'
libstdc++-v3/include/bits/exception_ptr.h:288:5: note: non-uglified whitelisted 
name 'swap'
libstdc++-v3/include/bits/fs_path.h:204:13: note: non-uglified whitelisted name 
'value_type'
libstdc++-v3/include/bits/funcwrap.h:437:6: note: non-uglified whitelisted name 
'swap'
libstdc++-v3/include/bits/iterator_concepts.h:106:12: note: non-uglified 
whitelisted name 'iter_move'
libstdc++-v3/include/bits/iterator_concepts.h:857:12: note: non-uglified 
whitelisted name 'iter_swap'
libstdc++-v3/include/bits/iterator_concepts.h:995:10: note: non-uglified 
whitelisted name 'begin'
libstdc++-v3/include/bits/move.h:231:5: note: non-uglified whitelisted name 
'swap'
libstdc++-v3/include/bits/ranges_base.h:147:10: note: non-uglified whitelisted 
name 'end'
libstdc++-v3/include/bits/ranges_base.h:197:10: note: non-uglified whitelisted 
name 'rbegin'
libstdc++-v3/include/bits/ranges_base.h:261:10: note: non-uglified whitelisted 
name 'rend'
libstdc++-v3/include/bits/ranges_base.h:319:10: note: non-uglified whitelisted 
name 'size'
libstdc++-v3/include/bits/stl_list.h:102:7: note: non-uglified whitelisted name 
'swap'
libstdc++-v3/include/charconv:364:3: note: non-uglified whitelisted name 
'to_chars'
libstdc++-v3/include/concepts:193:35: note: non-uglified whitelisted name 'swap'
libstdc++-v3/include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp:151:25:
 note: non-uglified whitelisted name 'other'
libstdc++-v3/include/ext/throw_allocator.h:124:18: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:124:28: note: non-uglified 
whitelisted name 'size'
libstdc++-v3/include/ext/throw_allocator.h:129:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:138:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:146:17: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:146:27: note: non-uglified 
whitelisted name 'size'
libstdc++-v3/include/ext/throw_allocator.h:151:28: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:155:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:162:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:170:27: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:176:27: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:176:37: note: non-uglified 
whitelisted name 'size'
libstdc++-v3/include/ext/throw_allocator.h:181:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:189:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:205:24: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:206:24: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:217:14: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:218:14: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:230:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:242:24: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:243:24: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:253:14: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:254:14: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:265:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:273:29: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:278:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:290:12: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:291:12: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:302:23: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:314:22: note: non-uglified 
whitelisted name 'p'
libstdc++-v3/include/ext/throw_allocator.h:314:32: note: non-uglified 
whitelisted name 'size'
libstdc++-v3/include/ext/throw_allocator.h:318:51: note: non-uglified 
whitelisted name 'ref'
libstdc++-v3/include/ext/throw_allocator.h:344:73: note: non-uglified 
whitelisted name 'ref'
libstdc++-v3/include/ext/throw_allocator.h:391:17: note: non-uglified 
whitelisted name 'error'
libstdc++-v3/include/ext/throw_allocator.h:394:33: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:395:33: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:401:12: note: non-uglified 
whitelisted name 'beg'
libstdc++-v3/include/ext/throw_allocator.h:402:12: note: non-uglified 
whitelisted name 'end'
libstdc++-v3/include/ext/throw_allocator.h:522:29: note: non-uglified 
whitelisted name 'size'
libstdc++-v3/include/ext/throw_allocator.h:575:19: note: non-uglified 
whitelisted name 'generator'
libstdc++-v3/include/format:1050:9: note: non-uglified whitelisted name 
'uint_least32_t'
libstdc++-v3/include/format:1310:5: note: non-uglified whitelisted name 'value'
libstdc++-v3/include/format:1320:10: note: non-uglified whitelisted name 
'has_value'
libstdc++-v3/include/format:3456:25: note: non-uglified whitelisted name 
'vector'
libstdc++-v3/include/print:181:24: note: non-uglified whitelisted name 'out'
libstdc++-v3/include/pstl/glue_algorithm_defs.h:143:107: note: non-uglified 
whitelisted name 'result'
libstdc++-v3/include/span:530:12: note: non-uglified whitelisted name 'data'
libstdc++-v3/include/span:531:12: note: non-uglified whitelisted name 'size'
libstdc++-v3/include/span:532:22: note: non-uglified whitelisted name 'extent'
libstdc++-v3/include/span:544:12: note: non-uglified whitelisted name 'data'
libstdc++-v3/include/span:545:12: note: non-uglified whitelisted name 'size'
libstdc++-v3/include/span:546:22: note: non-uglified whitelisted name 'extent'
libstdc++-v3/include/system_error:204:8: note: non-uglified whitelisted name 
'make_error_code'
libstdc++-v3/include/system_error:205:8: note: non-uglified whitelisted name 
'make_error_condition'
libstdc++-v3/include/system_error:243:27: note: non-uglified whitelisted name 
'make_error_code'
libstdc++-v3/include/system_error:376:27: note: non-uglified whitelisted name 
'make_error_condition'
libstdc++-v3/include/tr1/hashtable_policy.h:365:25: note: non-uglified 
whitelisted name 'result_type'
libstdc++-v3/include/tr1/tuple:426:21: note: non-uglified whitelisted name 
'ignore'
libstdc++-v3/include/type_traits:3055:5: note: non-uglified whitelisted name 
'swap'
libstdc++-v3/include/variant:170:39: note: non-uglified whitelisted name 'type'
libstdc++-v3/include/x86_64-pc-linux-gnu/bits/c++config.h:357:10: note: 
non-uglified whitelisted name 'terminate'

2026-03-17  Jakub Jelinek  <[email protected]>

        * g++.dg/plugin/plugin.exp (plugin_test_list): Add uglification tests.
        * g++.dg/plugin/uglification_plugin.cc: New file.
        * g++.dg/plugin/uglification-c++98.C: New test.
        * g++.dg/plugin/uglification-c++11.C: New test.
        * g++.dg/plugin/uglification-c++14.C: New test.
        * g++.dg/plugin/uglification-c++17.C: New test.
        * g++.dg/plugin/uglification-c++20.C: New test.
        * g++.dg/plugin/uglification-c++23.C: New test.
        * g++.dg/plugin/uglification-c++26.C: New test.

--- gcc/testsuite/g++.dg/plugin/plugin.exp.jj   2026-01-02 09:56:10.336333661 
+0100
+++ gcc/testsuite/g++.dg/plugin/plugin.exp      2026-03-17 16:54:28.967391245 
+0100
@@ -78,6 +78,14 @@ set plugin_test_list [list \
          show-template-tree-color-no-highlight-colors.C \
          show-template-tree-color-labels.C \
          show-template-tree-color-no-elide-type.C } \
+    { uglification_plugin.cc \
+         uglification-c++98.C \
+         uglification-c++11.C \
+         uglification-c++14.C \
+         uglification-c++17.C \
+         uglification-c++20.C \
+         uglification-c++23.C \
+         uglification-c++26.C } \
     { comment_plugin.cc comments-1.C } \
 ]
 
--- gcc/testsuite/g++.dg/plugin/uglification_plugin.cc.jj       2026-03-17 
16:37:46.128622695 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification_plugin.cc  2026-03-17 
18:49:01.359019835 +0100
@@ -0,0 +1,245 @@
+#include "gcc-plugin.h"
+#include <stdlib.h>
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree.h"
+#include "intl.h"
+#include "cp/cp-tree.h"
+#include "cp/name-lookup.h"
+#include "diagnostic.h"
+
+int plugin_is_GPL_compatible;
+
+void plugin_walk_ns (tree);
+
+const char *badnames[] = {
+  /* See libstdc++-v3/testsuite/17_intro/{,bad}names.cc.  */
+  "_A", "_B", "_C", "_G", "_L", "_N", "_P", "_S", "_T", "_U", "_X",
+  "__deref", "__used", "__unused", "__inline", "_Complex",
+  "__istype", "__maskrune", "__tolower", "__toupper", "__wchar_t",
+  "__wint_t", "_res", "_res_ext", "_C2", "__lockable", "__null_sentinel",
+  "__packed", "__weak", "__strong", "_In_", "_Inout_", "_Out_",
+  "_Reserved_", "__inout", "__in_opt", "__out_opt"
+};
+
+vec<tree> nonugly_names;
+hash_set<tree> whitelist;
+bool impl_ns;
+
+void
+plugin_check_decl (tree decl)
+{
+  if (decl == NULL_TREE)
+    return;
+
+  if (VAR_OR_FUNCTION_DECL_P (decl)
+      && DECL_EXTERNAL (decl)
+      && DECL_CONTEXT (decl)
+      && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL)
+    return;
+
+  tree name = DECL_NAME (decl);
+  if (name == NULL_TREE
+      || IDENTIFIER_ANON_P (name)
+      || name == this_identifier
+      || IDENTIFIER_ANY_OP_P (name))
+    return;
+
+  const char *cname = IDENTIFIER_POINTER (name);
+  if (cname[0] != '_'
+      || (cname[1] != '_'
+         && !ISUPPER (cname[1])
+         && cname[1]))
+    {
+      nonugly_names.safe_push (decl);
+      return;
+    }
+
+  bool badname = false;
+  for (int i = 0; i < ARRAY_SIZE (badnames); ++i)
+    if (strcmp (badnames[i], cname) == 0)
+      {
+       badname = true;
+       break;
+      }
+  if (!badname && cname[1] == 'E' && ISDIGIT (cname[2]))
+    {
+      if (cname[2] != '0'
+         && (!cname[3] || ((cname[2] == '1' || cname[2] == '2')
+                           && ISDIGIT (cname[3])
+                           && !cname[4])))
+       badname = true;
+    }
+  else if (memcmp (cname + 1, "_tg_", 4) == 0)
+    badname = true;
+  if (badname)
+    inform (DECL_SOURCE_LOCATION (decl), "badname %qs", cname);
+}
+
+tree
+plugin_check_tree (tree *tp, int */*walk_subtrees*/, void */*data*/)
+{
+  if (TREE_CODE (*tp) == BIND_EXPR)
+    for (tree var = BIND_EXPR_VARS (*tp); var; var = DECL_CHAIN (var))
+      plugin_check_decl (var);
+  if (TREE_CODE (*tp) == DECL_EXPR)
+    plugin_check_decl (DECL_EXPR_DECL (*tp));
+  return NULL_TREE;
+}
+
+void
+plugin_check_fn (tree decl)
+{
+  for (tree arg = DECL_ARGUMENTS (decl); arg; arg = DECL_CHAIN (arg))
+    plugin_check_decl (arg);
+
+  cp_walk_tree_without_duplicates (&DECL_SAVED_TREE (decl), plugin_check_tree,
+                                  NULL);
+}
+
+bool
+plugin_header_check (tree decl)
+{
+  expanded_location eloc = expand_location (DECL_SOURCE_LOCATION (decl));
+  if (eloc.file == NULL)
+    return false;
+  if (strstr (eloc.file, "/libstdc++-v3/include/") == NULL
+      && strstr (eloc.file, "/libstdc++-v3/libsupc++/") == NULL)
+    return false;
+  return true;
+}
+
+void
+plugin_walk_decl (tree decl)
+{
+  if (TREE_CODE (decl) == NAMESPACE_DECL)
+    {
+      if (impl_ns
+         || (DECL_NAME (decl)
+             && IDENTIFIER_POINTER (DECL_NAME (decl))[0] != '_')
+         || DECL_NAMESPACE_INLINE_P (decl))
+       plugin_walk_ns (decl);
+      else
+       {
+         impl_ns = true;
+         plugin_walk_ns (decl);
+         impl_ns = false;
+       }
+      return;
+    }
+
+  if (!plugin_header_check (decl))
+    return;
+
+  if (!impl_ns
+      && DECL_NAME (decl)
+      && !IDENTIFIER_ANON_P (DECL_NAME (decl))
+      && !IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
+      && IDENTIFIER_POINTER (DECL_NAME (decl))[0] != '_')
+    whitelist.add (DECL_NAME (decl));
+  else if (impl_ns && DECL_NAME (decl))
+    plugin_check_decl (decl);
+
+  if (TREE_CODE (decl) == TEMPLATE_DECL)
+    {
+      tree parms = DECL_INNERMOST_TEMPLATE_PARMS (decl);
+      for (tree node : tree_vec_range (parms))
+       plugin_check_decl (TREE_VALUE (node));
+    }
+
+  if (DECL_FUNCTION_TEMPLATE_P (decl))
+    plugin_check_fn (DECL_TEMPLATE_RESULT (decl));
+
+  if (TREE_CODE (decl) == TYPE_DECL
+      && DECL_IMPLICIT_TYPEDEF_P (decl))
+    {
+      if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
+       for (tree fld = TYPE_FIELDS (TREE_TYPE (decl));
+            fld; fld = DECL_CHAIN (fld))
+         plugin_walk_decl (fld);
+      else if (TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
+       for (tree en = TYPE_VALUES (TREE_TYPE (decl));
+            en; en = TREE_CHAIN (en))
+         plugin_walk_decl (TREE_VALUE (en));
+    }
+}
+
+void
+plugin_walk_binding (tree binding)
+{
+  tree value = NULL_TREE;
+
+  if (STAT_HACK_P (binding))
+    {
+      if (!STAT_TYPE_HIDDEN_P (binding)
+          && STAT_TYPE (binding))
+        return plugin_walk_decl (STAT_TYPE (binding));
+      else if (!STAT_DECL_HIDDEN_P (binding))
+        value = STAT_DECL (binding);
+    }
+  else
+    value = binding;
+
+  value = ovl_skip_hidden (value);
+  if (value)
+    {
+      value = OVL_FIRST (value);
+      return plugin_walk_decl (value);
+    }
+}
+
+void
+plugin_walk_ns (tree ns)
+{
+  using itert = hash_table<named_decl_hash>::iterator;
+  itert end (DECL_NAMESPACE_BINDINGS (ns)->end ());
+  for (itert iter (DECL_NAMESPACE_BINDINGS (ns)->begin ());
+       iter != end; ++iter)
+    {
+      tree b = *iter;
+      gcc_assert (TREE_CODE (b) != BINDING_VECTOR);
+      plugin_walk_binding (b);
+    }
+}
+
+void
+plugin_finish_parse_function (void *event_data, void *)
+{
+  tree decl = (tree) event_data;
+  if (!plugin_header_check (decl))
+    return;
+
+  /* Templates are handled from plugin_walk_ns.  */
+  if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
+    return;
+  plugin_check_fn (decl);
+}
+
+void
+plugin_finish_unit (void *, void *)
+{
+  plugin_walk_ns (std_node);
+  unsigned int i;
+  tree decl;
+  FOR_EACH_VEC_ELT (nonugly_names, i, decl)
+    if (!whitelist.contains (DECL_NAME (decl)))
+      inform (DECL_SOURCE_LOCATION (decl), "non-uglified name %qs",
+             IDENTIFIER_POINTER (DECL_NAME (decl)));
+    else
+      inform (DECL_SOURCE_LOCATION (decl), "non-uglified whitelisted name %qs",
+             IDENTIFIER_POINTER (DECL_NAME (decl)));
+}
+
+int
+plugin_init (struct plugin_name_args *plugin_info,
+             struct plugin_gcc_version *version)
+{
+  const char *plugin_name = plugin_info->base_name;
+
+  register_callback (plugin_name, PLUGIN_FINISH_UNIT,
+                     plugin_finish_unit, NULL);
+  register_callback (plugin_name, PLUGIN_FINISH_PARSE_FUNCTION,
+                    plugin_finish_parse_function, NULL);
+  return 0;
+}
--- gcc/testsuite/g++.dg/plugin/uglification-c++98.C.jj 2026-03-17 
16:52:27.238446844 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++98.C    2026-03-17 
16:52:40.508222726 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++98" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++11.C.jj 2026-03-17 
16:52:52.727016358 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++11.C    2026-03-17 
16:52:56.556951673 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++11" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++14.C.jj 2026-03-17 
16:53:46.707104669 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++14.C    2026-03-17 
16:53:16.031622759 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++14" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++17.C.jj 2026-03-17 
16:54:00.757867359 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++17.C    2026-03-17 
16:53:21.357532805 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++17" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++20.C.jj 2026-03-17 
16:54:00.757867359 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++20.C    2026-03-17 
16:53:27.575427792 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++20" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++23.C.jj 2026-03-17 
16:54:00.757867359 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++23.C    2026-03-17 
16:53:36.641274675 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++23" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }
--- gcc/testsuite/g++.dg/plugin/uglification-c++26.C.jj 2026-03-17 
16:54:00.757867359 +0100
+++ gcc/testsuite/g++.dg/plugin/uglification-c++26.C    2026-03-17 
16:53:41.819187221 +0100
@@ -0,0 +1,10 @@
+// Verify template parameter names, names of arguments and block scope decls
+// in functions and function templates are uglified and don't contain
+// badnames.
+// { dg-options "-O0 -std=c++26" }
+
+#include <bits/stdc++.h>
+#include <bits/extc++.h>
+
+// { dg-bogus "note: non-uglified name" "" { target *-*-* } 0 }
+// { dg-bogus "note: badname" "" { target *-*-* } 0 }


        Jakub

Reply via email to