From bb5d862a84817e59cf971b1064835508c13f5bb0 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 8 Mar 2016 21:31:32 +0000 Subject: [PATCH] Silence duplicate diagnostics because parsing of a standards-based attribute triggers parsing diagnostics that may also be picked up during semantic analysis. llvm-svn: 262960 --- clang/lib/Parse/ParseDeclCXX.cpp | 2 ++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp | 8 ++++++++ clang/test/Parser/cxx0x-attributes.cpp | 1 - 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 15aded5..354e405 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -3695,6 +3695,7 @@ bool Parser::ParseCXX11AttributeArgs(IdentifierInfo *AttrName, // The attribute was allowed to have arguments, but none were provided // even though the attribute parsed successfully. This is an error. Diag(LParenLoc, diag::err_attribute_requires_arguments) << AttrName; + Attr->setInvalid(true); } else if (!Attr->getMaxArgs()) { // The attribute parsed successfully, but was not allowed to have any // arguments. It doesn't matter whether any were provided -- the @@ -3702,6 +3703,7 @@ bool Parser::ParseCXX11AttributeArgs(IdentifierInfo *AttrName, Diag(LParenLoc, diag::err_cxx11_attribute_forbids_arguments) << AttrName << FixItHint::CreateRemoval(SourceRange(LParenLoc, *EndLoc)); + Attr->setInvalid(true); } } } diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp new file mode 100644 index 0000000..b6f8e7b --- /dev/null +++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s + +struct [[nodiscard]] S1 {}; // ok +struct [[nodiscard nodiscard]] S2 {}; // expected-error {{attribute 'nodiscard' cannot appear multiple times in an attribute specifier}} +struct [[nodiscard("Wrong")]] S3 {}; // expected-error {{'nodiscard' cannot have an argument list}} + +[[nodiscard]] int f(); +enum [[nodiscard]] E {}; diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index c032e47..906d72b 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -336,7 +336,6 @@ namespace { // expected-warning@-1 {{use of the 'deprecated' attribute is a C++14 extension}} [[deprecated()]] void foo(); // expected-error@-1 {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} - // expected-warning@-2 {{use of the 'deprecated' attribute is a C++14 extension}} [[gnu::deprecated()]] void quux(); } -- 2.7.4