From 9bfb2ed20480e7858532b677280549a79e5690c3 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 15 Oct 2026 13:24:13 -0400 Subject: [PATCH 1/2] Recognize an attribute namespace only on an exact name match. [GH #305] --- src/Changes | 11 +++++ src/attribute.c | 4 +- .../changes/.GH-ns-exact.rto/default.1.1.txt | 41 +++++++++++++++++++ .../.GH-ns-exact.rto/default.1.matches.txt | 24 +++++++++++ .../.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt | 21 ++++++++++ tests/tests/changes/GH-ns-exact.sft.cpp | 29 +++++++++++++ 6 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt create mode 100644 tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt create mode 100644 tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt create mode 100644 tests/tests/changes/GH-ns-exact.sft.cpp diff --git a/src/Changes b/src/Changes index de5c529b76..df3a576af0 100644 --- a/src/Changes +++ b/src/Changes @@ -1,5 +1,16 @@ Version 7.1 +10/15/26 [GH #305] +Attribute namespaces that only start like a known one are not recognized + +An attribute namespace was treated as known if it was merely the first part +of the name of a known namespace, so a namespace such as "cl", "g" or "ms" +was accepted as if it were "clang", "gnu" or "msvc". The whole name must +now match. For example: + + [[cl::x]] int a; // Warning: attribute namespace "cl" is unrecognized + [[g::y]] int b; // Previously, the namespace was accepted. + 10/9/26 [GH #27] Clearer diagnostic when auto is deduced from an incomplete type diff --git a/src/attribute.c b/src/attribute.c index 86c8b0a627..630f4a949c 100644 --- a/src/attribute.c +++ b/src/attribute.c @@ -1096,7 +1096,9 @@ namespace. If non-zero, length represents the number of characters in name length = strlen(name); } /* if */ for (np = valid_attribute_namespaces; *np != NULL; np++) { - if (strncmp(*np, name, length) == 0) { + /* The whole name must match: a name that is only a prefix of a known + namespace (e.g., "cl" or "g") is not recognized. */ + if (strncmp(*np, name, length) == 0 && (*np)[length] == '\0') { result = TRUE; break; } /* if */ diff --git a/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt new file mode 100644 index 0000000000..f4be6205c7 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt @@ -0,0 +1,41 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + +"Test_name.c", line 25: warning: unknown attribute "gnu::x" + [[gnu::x]] int f; + ^ + +"Test_name.c", line 26: warning: unknown attribute "__gnu__::x" + [[__gnu__::x]] int g; + ^ + +"Test_name.c", line 27: warning: unknown attribute "clang::x" + [[clang::x]] int h; + ^ + +"Test_name.c", line 28: warning: unknown attribute "msvc::x" + [[msvc::x]] int i; + ^ + +"Test_name.c", line 29: warning: unknown attribute "_Clang::x" + [[_Clang::x]] int j; + ^ + diff --git a/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt b/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt new file mode 100644 index 0000000000..9aa901a538 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt @@ -0,0 +1,24 @@ +Matches for "attribute namespace "cl" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "cl" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "gn" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "gn" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "g" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "g" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "ms" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "ms" is unrecognized + -----------------------------------------------------------------------------> +Matches for "attribute namespace "_Cl" is unrecognized": + <----------------------------------------------------------------------------- + attribute namespace "_Cl" is unrecognized + -----------------------------------------------------------------------------> +Matches for "\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized)": + <----------------------------------------------------------------------------- + + -----------------------------------------------------------------------------> diff --git a/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt new file mode 100644 index 0000000000..c601710a51 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt @@ -0,0 +1,21 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + diff --git a/tests/tests/changes/GH-ns-exact.sft.cpp b/tests/tests/changes/GH-ns-exact.sft.cpp new file mode 100644 index 0000000000..2d8907232d --- /dev/null +++ b/tests/tests/changes/GH-ns-exact.sft.cpp @@ -0,0 +1,29 @@ +//type:fp +//options:--c++17 +//remark:[GH #?] Attribute namespaces that only start like a known one +//match_regex:attribute namespace "cl" is unrecognized +//match_regex:attribute namespace "gn" is unrecognized +//match_regex:attribute namespace "g" is unrecognized +//match_regex:attribute namespace "ms" is unrecognized +//match_regex:attribute namespace "_Cl" is unrecognized +//match_regex:\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized) +// 10/14/26 [GH #?] +// +// A namespace that is only a prefix of a namespace known to the front end +// ("clang", "gnu", "msvc", "_Clang") is not recognized: it gets the +// "attribute namespace is unrecognized" warning like any other unknown one. +// The known namespaces themselves are still recognized: they get the +// "unknown attribute" warning for the unknown attribute name only (the last +// regular expression above fails if one of them is reported as unrecognized). + +[[cl::x]] int a; +[[gn::y]] int b; +[[g::z]] int c; +[[ms::w]] int d; +[[_Cl::v]] int e; + +[[gnu::x]] int f; +[[__gnu__::x]] int g; +[[clang::x]] int h; +[[msvc::x]] int i; +[[_Clang::x]] int j; From 5e8521923de861728a7edee24dd8440559633769 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 15 Oct 2026 14:35:22 -0400 Subject: [PATCH 2/2] Add missing x32 recording [] --- .../.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt | 21 +++++++++++++++++++ tests/tests/changes/GH-ns-exact.sft.cpp | 4 ++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt diff --git a/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt new file mode 100644 index 0000000000..c601710a51 --- /dev/null +++ b/tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt @@ -0,0 +1,21 @@ +fe_only -DTEST_NUMBER=1 --c++17 Test_name.c +"Test_name.c", line 19: warning: attribute namespace "cl" is unrecognized + [[cl::x]] int a; + ^ + +"Test_name.c", line 20: warning: attribute namespace "gn" is unrecognized + [[gn::y]] int b; + ^ + +"Test_name.c", line 21: warning: attribute namespace "g" is unrecognized + [[g::z]] int c; + ^ + +"Test_name.c", line 22: warning: attribute namespace "ms" is unrecognized + [[ms::w]] int d; + ^ + +"Test_name.c", line 23: warning: attribute namespace "_Cl" is unrecognized + [[_Cl::v]] int e; + ^ + diff --git a/tests/tests/changes/GH-ns-exact.sft.cpp b/tests/tests/changes/GH-ns-exact.sft.cpp index 2d8907232d..da5409fb5b 100644 --- a/tests/tests/changes/GH-ns-exact.sft.cpp +++ b/tests/tests/changes/GH-ns-exact.sft.cpp @@ -1,13 +1,13 @@ //type:fp //options:--c++17 -//remark:[GH #?] Attribute namespaces that only start like a known one +//remark:[GH #305] Attribute namespaces that only start like a known one //match_regex:attribute namespace "cl" is unrecognized //match_regex:attribute namespace "gn" is unrecognized //match_regex:attribute namespace "g" is unrecognized //match_regex:attribute namespace "ms" is unrecognized //match_regex:attribute namespace "_Cl" is unrecognized //match_regex:\A(?![\s\S]*attribute namespace "(gnu|__gnu__|clang|_Clang|msvc)" is unrecognized) -// 10/14/26 [GH #?] +// 10/14/26 [GH #305] // // A namespace that is only a prefix of a namespace known to the front end // ("clang", "gnu", "msvc", "_Clang") is not recognized: it gets the