Commit Graph

37 Commits

Author SHA1 Message Date
Aaron Ballman ef5d94caf0 Fixing a typo, updating the diagnostic wording and logic based on post-commit review feedback. Amends r206186.
llvm-svn: 206229
2014-04-15 00:36:39 +00:00
Aaron Ballman 35f9421c55 Properly diagnose standard C++ attributes which have optional argument lists when the arguments are elided. eg)
[[deprecated()]] // error
[[deprecated]] // OK
[[deprecated("")]] // OK
[[gnu::deprecated()]] // OK

llvm-svn: 206186
2014-04-14 16:03:22 +00:00
Aaron Ballman b8e203939e Introduced an attribute syntax-neutral method for parsing attribute arguments that is currently being used by GNU and C++-style attributes. This allows C++11 attributes with argument lists to be handled properly, fixing the "deprecated", "type_visibility", and capability-related attributes with arguments.
llvm-svn: 205226
2014-03-31 17:32:39 +00:00
Saleem Abdulrasool 73196baef4 add an additional test case for generic attributes
gcc treats [[gnu:const]], [[gnu::__const]], and [[gnu:__const__]] as all being
equivalent.  Add an additional test case to ensure that we do not miss the last
case.

llvm-svn: 195982
2013-11-30 21:17:12 +00:00
Aaron Ballman 3a8e2d9136 Adding the Subjects entry back for the noreturn attributes. This caused some test cases to be updated because the original diagnostic was about applying to methods as well as functions, but the semantic checking disallowed methods.
llvm-svn: 195862
2013-11-27 18:53:58 +00:00
Nick Lewycky 2c531165ff Add missing attributes [[gnu::no_sanitize_address]] and
[[gnu::no_address_safety_analysis]].

llvm-svn: 193583
2013-10-29 03:54:41 +00:00
Nick Lewycky d0604672d9 Treat [[gnu::__const]] the same as [[gnu::const]]. GCC's tokenizer can't tell
the difference.

llvm-svn: 193582
2013-10-29 03:33:57 +00:00
Richard Smith c2c8bb8209 Tidy up and improve error recovery for C++11 attributes in bad places. Based on
a patch by Michael Han.

llvm-svn: 192666
2013-10-15 01:34:54 +00:00
Richard Smith f216366e64 C++11 attributes after 'constructor-name (' unambiguously signal that we have a
constructor.

llvm-svn: 190111
2013-09-06 00:12:20 +00:00
Michael Han 84324357b8 [Sema] Semantic analysis for empty-declaration and attribute-declaration.
Introduce a new AST Decl node "EmptyDecl" to model empty-declaration. Have attributes from attribute-declaration appertain
to the EmptyDecl node by creating the AST representations of these attributes and attach them to the EmptyDecl node so these
attributes can be sema checked just as attributes attached to "normal" declarations.

llvm-svn: 175900
2013-02-22 17:15:32 +00:00
Richard Smith 2386c8b221 Per the grammar in [dcl.dcl]p1, a simple-declaration can only have attributes
if it has declarators. We were missing the check for this in a couple of places.

llvm-svn: 175876
2013-02-22 09:06:26 +00:00
Richard Smith 54ecd9863f Process and handle attributes on conditions and for loop variables. Process and
diagnose attributes on alias declarations, using directives, and attribute
declarations.

llvm-svn: 175649
2013-02-20 19:22:51 +00:00
Richard Smith 810ad3eb44 Downgrade 'attribute ignored when parsing type' from error to warning, to match
the diagnostic's warn_ name. Switch some places (notably C++11 attributes)
which really wanted an error over to a different diagnostic. Finally, suppress
the diagnostic entirely for __ptr32, __ptr64 and __w64, to avoid producing
diagnostics in important system headers.

llvm-svn: 173788
2013-01-29 10:02:16 +00:00
Richard Smith 10876ef571 Implement C++11 semantics for [[noreturn]] attribute. This required splitting
it apart from [[gnu::noreturn]] / __attribute__((noreturn)), since their
semantics are not equivalent (for instance, we treat [[gnu::noreturn]] as
affecting the function type, whereas [[noreturn]] does not).

llvm-svn: 172691
2013-01-17 01:30:42 +00:00
Richard Smith 368ca52cd9 Accept [[gnu::*]] for all __attribute__((*))s which are:
1) Supported by Clang, and
 2) Supported by GCC, and
 3) Documented in GCC's manual.

g++ allows its C++11-style attributes to appertain only to the entity being
declared, and never to a type (even for a type attribute), so we do the same.

llvm-svn: 172382
2013-01-14 07:53:01 +00:00
Michael Han 309af291ef Add fixit hints for misplaced C++11 attributes around class specifiers.
Following r168626, in class declaration or definition, there are a combination of syntactic locations 
where C++11 attributes could appear, and among those the only valid location permitted by standard is
between class-key and class-name. So for those attributes appear at wrong locations, fixit is used to 
move them to expected location and we recover by applying them to the class specifier.
 

llvm-svn: 171757
2013-01-07 16:57:11 +00:00
Michael Han ddc016d4d7 Implement C++11 [dcl.attr.grammar] p4: If an attribute-specifier-seq appertains to a friend declaration, that declaration shall be a definition.
llvm-svn: 168826
2012-11-28 23:17:40 +00:00
Michael Han 9407e50b04 Improve diagnostic on C++11 attribute specifiers that appear at wrong syntactic locations around class specifiers.
This change list implemented logic that explicitly detects several combinations of locations where C++11 attribute
specifiers might be incorrectly placed within a class specifier. Previously we emit generic diagnostics like 
"expected identifier" for such cases; now we emit specific diagnostic against the misplaced attributes, this also 
fixed a bug in old code where attributes appear at legitimate locations were incorrectly rejected.

Thanks to Richard Smith for reviewing!

llvm-svn: 168626
2012-11-26 22:54:45 +00:00
Michael Han 64536a6d25 Teach Clang parser to reject C++11 attributes that appertain to declaration specifiers.
We don't support any C++11 attributes that appertain to declaration specifiers so reject 
the attributes in parser until we support them; this also conforms to what g++ 4.8 is doing.

llvm-svn: 167481
2012-11-06 19:34:54 +00:00
Michael Han 23214e5046 Improve C++11 attribute parsing.
- General C++11 attributes were previously parsed and ignored. Now they are parsed and stored in AST.
- Add support to parse arguments of attributes that in 'gnu' namespace.
- Differentiate unknown attributes and known attributes that can't be applied to statements when emitting diagnostic.

llvm-svn: 165082
2012-10-03 01:56:22 +00:00
John McCall beae29a5f4 Recognize GNU attributes after 'enum class'. Fixes the libc++ build.
llvm-svn: 159089
2012-06-23 22:30:04 +00:00
Alexis Hunt 6aa9beef50 Clean up a large number of C++11 attribute parse issues, including parsing
attributes in more places where we didn't and catching a lot more issues.

This implements nearly every aspect of C++11 attribute parsing, except for:
 - Attributes are permitted on explicit instantiations inside the declarator
   (but not preceding the decl-spec)
 - Attributes are permitted on friend declarations of functions.
 - Multiple instances of the same attribute in an attribute-list (e.g.
   [[noreturn, noreturn]], not [[noreturn]] [[noreturn]] which is conforming)
   are allowed.
The first two are marked as expected-FIXME in the test file and the latter
is probably a defect and is currently untested.

Thanks to Richard Smith for providing the lion's share of the testcases.

llvm-svn: 159072
2012-06-23 05:07:58 +00:00
Richard Smith 2620cd9903 Support C++11 attributes at the start of a parameter-declaration.
llvm-svn: 154476
2012-04-11 04:01:28 +00:00
Richard Smith 3dff251da1 Parsing of C++11 attributes:
* Alternative tokens (such as 'compl') are treated as identifiers in
   attribute names.
 * An attribute-list can start with a comma.
 * An ellipsis may not be used with either of our currently-supported
   C++11 attributes.

llvm-svn: 154381
2012-04-10 03:25:07 +00:00
Richard Smith 7bdcc4a9da Disambiguation of '[[':
* In C++11, '[[' is ill-formed unless it starts an attribute-specifier. Reject
   array sizes and array indexes which begin with a lambda-expression. Recover by
   parsing the lambda as a lambda.
 * In Objective-C++11, either '[' could be the start of a message-send.
   Fully disambiguate this case: it turns out that the grammars of message-sends,
   lambdas and attributes do not actually overlap. Accept any occurrence of '[['
   where either '[' starts a message send, but reject a lambda in an array index
   just like in C++11 mode.

Implement a couple of changes to the attribute wording which occurred after our
attributes implementation landed:
 * In a function-declaration, the attributes go after the exception specification,
   not after the right paren.
 * A reference type can have attributes applied.
 * An 'identifier' in an attribute can also be a keyword. Support for alternative
   tokens (iso646 keywords) in attributes to follow.

And some bug fixes:
 * Parse attributes after declarator-ids, even if they are not simple identifiers.
 * Do not accept attributes after a parenthesized declarator.
 * Accept attributes after an array size in a new-type-id.
 * Partially disamiguate 'delete' followed by a lambda. More work is required
   here for the case where the lambda-introducer is '[]'.

llvm-svn: 154369
2012-04-10 01:32:12 +00:00
Richard Smith f4c51d9d76 In C++11 mode, when an integral constant expression is desired and we have a
value of class type, look for a unique conversion operator converting to
integral or unscoped enumeration type and use that. Implements [expr.const]p5.

Sema::VerifyIntegerConstantExpression now performs the conversion and returns
the converted result. Some important callers of Expr::isIntegralConstantExpr
have been switched over to using it (including all of those required for C++11
conformance); this switch brings a side-benefit of improved diagnostics and, in
several cases, simpler code. However, some language extensions and attributes
have not been moved across and will not perform implicit conversions on
constant expressions of literal class type where an ICE is required.

In passing, fix static_assert to perform a contextual conversion to bool on its
argument.

llvm-svn: 149776
2012-02-04 09:53:13 +00:00
Eli Friedman c7c97144af Stub out the Sema interface for lambda expressions, and change the parser to use it. Unconditionally error on lambda expressions because they don't work in any meaningful way yet.
llvm-svn: 147515
2012-01-04 02:40:39 +00:00
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Peter Collingbourne 2f3cf4b158 Add support for alignment-specifiers in C1X and C++11, remove
support for the C++0x draft [[align]] attribute and add the C1X
standard header file stdalign.h

llvm-svn: 140796
2011-09-29 18:04:28 +00:00
Peter Collingbourne 49eedecd70 Add support for parsing an attribute-specifier-seq containing multiple
attribute-specifiers

llvm-svn: 140794
2011-09-29 18:04:05 +00:00
Peter Collingbourne 70188b3fc2 Add support for parsing the optional attribute-specifier-seq at the
end of a decl-specifier-seq

llvm-svn: 140793
2011-09-29 18:03:57 +00:00
Douglas Gregor db0b9f1264 Parsing of C++0x lambda expressions, from John Freeman with help from
David Blaikie!

llvm-svn: 136876
2011-08-04 15:30:47 +00:00
Anders Carlsson 6774b1f1c1 Add -fcxx-exceptions to all tests that use C++ exceptions.
llvm-svn: 126599
2011-02-28 00:40:07 +00:00
Anders Carlsson 479d6f51e3 Pass -fexceptions to all tests that use try/catch/throw.
llvm-svn: 126037
2011-02-19 19:23:03 +00:00
Anders Carlsson 19588aa40b Get rid of the [[final]] C++0x attribute.
llvm-svn: 124083
2011-01-23 21:07:30 +00:00
Daniel Dunbar 8fbe78f6fc Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- This is designed to make it obvious that %clang_cc1 is a "test variable"
   which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it
   can be useful to redefine what gets run as 'clang -cc1' (for example, to set
   a default target).

llvm-svn: 91446
2009-12-15 20:14:24 +00:00
Alexis Hunt 96d5c76498 Added rudimentary C++0x attribute support.
The following attributes are currently supported in C++0x attribute
lists (and in GNU ones as well):
 - align() - semantics believed to be conformant to n3000, except for
   redeclarations and what entities it may apply to
 - final - semantics believed to be conformant to CWG issue 817's proposed
   wording, except for redeclarations
 - noreturn - semantics believed to be conformant to n3000, except for
   redeclarations
 - carries_dependency - currently ignored (this is an optimization hint)

llvm-svn: 89543
2009-11-21 08:43:09 +00:00