diff options
author | Marek Polacek <polacek@redhat.com> | 2019-06-17 18:26:07 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-06-17 18:26:07 +0000 |
commit | bf0af866a4f2792a91310d8b809e25ffbdd9e1f7 (patch) | |
tree | 1c6bfeed0fb062867b62eece6c2d3cc9b4605b54 | |
parent | 39f901e918c42935d1acf5ad87b79ae1b38a666b (diff) | |
download | gcc-bf0af866a4f2792a91310d8b809e25ffbdd9e1f7.zip gcc-bf0af866a4f2792a91310d8b809e25ffbdd9e1f7.tar.gz gcc-bf0af866a4f2792a91310d8b809e25ffbdd9e1f7.tar.bz2 |
PR c++/83820 - excessive attribute arguments not detected.
* parser.c (cp_parser_std_attribute): Detect excessive arguments.
* g++.dg/cpp0x/gen-attrs-67.C: New test.
From-SVN: r272395
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/parser.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/gen-attrs-67.C | 11 |
4 files changed, 35 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4e6d626..7368daf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-06-17 Marek Polacek <polacek@redhat.com> + + PR c++/83820 - excessive attribute arguments not detected. + * parser.c (cp_parser_std_attribute): Detect excessive arguments. + 2019-06-17 Nathan Sidwell <nathan@acm.org> PR c++/90754 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8f5ae84..6b4aab8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -26149,6 +26149,20 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) vec<tree, va_gc> *vec; int attr_flag = normal_attr; + /* Maybe we don't expect to see any arguments for this attribute. */ + const attribute_spec *as + = lookup_attribute_spec (TREE_PURPOSE (attribute)); + if (as && as->max_length == 0) + { + error_at (token->location, "%qE attribute does not take any arguments", + attr_id); + cp_parser_skip_to_closing_parenthesis (parser, + /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + return error_mark_node; + } + if (attr_ns == gnu_identifier && attribute_takes_identifier_p (attr_id)) /* A GNU attribute that takes an identifier in parameter. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13cd469..688c6f3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-17 Marek Polacek <polacek@redhat.com> + + PR c++/83820 - excessive attribute arguments not detected. + * g++.dg/cpp0x/gen-attrs-67.C: New test. + 2019-06-17 Nathan Sidwell <nathan@acm.org> PR c++/90754 diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-67.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-67.C new file mode 100644 index 0000000..93f55c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-67.C @@ -0,0 +1,11 @@ +// PR c++/83820 - excessive attribute arguments not detected. +// { dg-do compile { target c++11 } } + +[[noreturn()]] void f0 (); // { dg-error ".noreturn. attribute does not take any arguments" } +[[noreturn(1)]] void f1 (); // { dg-error ".noreturn. attribute does not take any arguments" } +[[noreturn(1, 2)]] void f2 (); // { dg-error ".noreturn. attribute does not take any arguments" } +[[maybe_unused()]] int f3(); // { dg-error ".maybe_unused. attribute does not take any arguments" } +[[nodiscard()]] int f4(); // { dg-error ".nodiscard. attribute does not take any arguments" } +[[gnu::noinline()]] int f5(); // { dg-error ".noinline. attribute does not take any arguments" } +[[gnu::constructor]] int f6(); +[[gnu::constructor(101)]] int f7(); |