public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649]
@ 2021-12-16 22:35 Marek Polacek
  2021-12-16 22:53 ` Jakub Jelinek
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Polacek @ 2021-12-16 22:35 UTC (permalink / raw)
  To: GCC Patches, Jakub Jelinek, Jason Merrill, Joseph Myers

My patch to implement -Wno-attribute=A::b caused a bogus error when
parsing

  [[foo::bar(1, 2)]];

when -Wno-attributes=foo::bar was specified on the command line, because
when we create a fake foo::bar attribute and insert it into our attribute
table, it is created with max_length == 0 which doesn't allow any args.
That is wrong -- we know nothing about the attribute, so we shouldn't
require any specific number of arguments.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	PR c/103649

gcc/ChangeLog:

	* attribs.c (handle_ignored_attributes_option): Create the fake
	attribute with max_length == -1.

gcc/testsuite/ChangeLog:

	* c-c++-common/Wno-attributes-6.c: New test.
---
 gcc/attribs.c                                 | 2 +-
 gcc/testsuite/c-c++-common/Wno-attributes-6.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/Wno-attributes-6.c

diff --git a/gcc/attribs.c b/gcc/attribs.c
index 29703e75fba..4933f020f1a 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -304,7 +304,7 @@ handle_ignored_attributes_option (vec<char *> *v)
 	 We can't free it here, so squirrel away the pointers.  */
       attribute_spec *table = new attribute_spec[2];
       ignored_attributes_table.safe_push (table);
-      table[0] = { attr, 0, 0, false, false, false, false, nullptr, nullptr };
+      table[0] = { attr, 0, -1, false, false, false, false, nullptr, nullptr };
       table[1] = { nullptr, 0, 0, false, false, false, false, nullptr,
 		   nullptr };
       register_scoped_attributes (table, IDENTIFIER_POINTER (vendor_id), !attr);
diff --git a/gcc/testsuite/c-c++-common/Wno-attributes-6.c b/gcc/testsuite/c-c++-common/Wno-attributes-6.c
new file mode 100644
index 00000000000..02cdaaa1e89
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/Wno-attributes-6.c
@@ -0,0 +1,9 @@
+/* PR c/103649 */
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-Wno-attributes=foo::bar" } */
+/* { dg-additional-options "-Wno-attributes=baz::" } */
+
+[[foo::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */
+[[baz::bar(1, 2)]]; /* { dg-warning "attribute ignored" } */
+[[foo::bar(1, 2)]] void f1();
+[[baz::bar(1, 2)]] void f2();

base-commit: f91814c22595e1db642140efe030caf2c092ab6f
-- 
2.33.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-17 22:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 22:35 [PATCH] attribs: Fix wrong error with -Wno-attribute=A::b [PR103649] Marek Polacek
2021-12-16 22:53 ` Jakub Jelinek
2021-12-17  0:52   ` [PATCH v2] " Marek Polacek
2021-12-17  1:06     ` Jason Merrill
2021-12-17 18:14       ` [PATCH v3] " Marek Polacek
2021-12-17 19:33         ` Jason Merrill
2021-12-17 22:56           ` [PATCH v4] " Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).