Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Changes
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
41 changes: 41 additions & 0 deletions tests/tests/changes/.GH-ns-exact.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -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;
^

24 changes: 24 additions & 0 deletions tests/tests/changes/.GH-ns-exact.rto/default.1.matches.txt
Original file line number Diff line number Diff line change
@@ -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)":
<-----------------------------------------------------------------------------

----------------------------------------------------------------------------->
21 changes: 21 additions & 0 deletions tests/tests/changes/.GH-ns-exact.rto/edg_x86_32_cp.1.1.txt
Original file line number Diff line number Diff line change
@@ -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;
^

21 changes: 21 additions & 0 deletions tests/tests/changes/.GH-ns-exact.rto/edg_x86_64_cp.1.1.txt
Original file line number Diff line number Diff line change
@@ -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;
^

29 changes: 29 additions & 0 deletions tests/tests/changes/GH-ns-exact.sft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//type:fp
//options:--c++17
//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 #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
// "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;
Loading