https://github.com/nehaGautam07 updated https://github.com/llvm/llvm-project/pull/220259
>From a3a00800f93a4d498dc83242faf0680cf360ccab Mon Sep 17 00:00:00 2001 From: neharaj <[email protected]> Date: Sat, 5 Sep 2026 11:52:10 +0000 Subject: [PATCH] [Clang][Parser] Reject unbalanced unknown attribute arguments --- clang/include/clang/Parse/Parser.h | 187 ++++++++-------- clang/lib/Parse/ParseDeclCXX.cpp | 91 +++----- clang/lib/Parse/Parser.cpp | 201 +++++++++--------- .../Parser/cxx11-unbalanced-attr-args.cpp | 7 + 4 files changed, 238 insertions(+), 248 deletions(-) create mode 100644 clang/test/Parser/cxx11-unbalanced-attr-args.cpp diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index ae91153e34e3a..f1613de67b520 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -316,7 +316,8 @@ class Parser : public CodeCompletionHandler { /// [C] translation-unit external-declaration /// [C++] top-level-declaration-seq[opt] /// [C++20] global-module-fragment[opt] module-declaration - /// top-level-declaration-seq[opt] private-module-fragment[opt] + /// top-level-declaration-seq[opt] + /// private-module-fragment[opt] /// \endverbatim /// /// Note that in C, it is an error if there is no first declaration. @@ -570,7 +571,9 @@ class Parser : public CodeCompletionHandler { StopAtSemi = 1 << 0, ///< Stop skipping at semicolon /// Stop skipping at specified token, but don't skip the token itself StopBeforeMatch = 1 << 1, - StopAtCodeCompletion = 1 << 2 ///< Stop at code completion + StopAtCodeCompletion = 1 << 2, ///< Stop at code completion + /// Do not swallow an unmatched ')', ']', or '}'. + StopAtUnbalanced = 1 << 3 }; friend constexpr SkipUntilFlags operator|(SkipUntilFlags L, @@ -1020,15 +1023,16 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// function-definition: [C99 6.9.1] - /// decl-specs declarator declaration-list[opt] compound-statement + /// decl-specs declarator declaration-list[opt] + /// compound-statement /// [C90] function-definition: [C99 6.7.1] - implicit int result - /// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement + /// [C90] decl-specs[opt] declarator declaration-list[opt] + /// compound-statement /// /// declaration: [C99 6.7] /// declaration-specifiers init-declarator-list[opt] ';' - /// [!C99] init-declarator-list ';' [TODO: warn in c99 mode] - /// [OMP] threadprivate-directive - /// [OMP] allocate-directive [TODO] + /// [!C99] init-declarator-list ';' [TODO: warn in c99 + /// mode] [OMP] threadprivate-directive [OMP] allocate-directive [TODO] /// \endverbatim /// DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs, @@ -1046,10 +1050,11 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// function-definition: [C99 6.9.1] - /// decl-specs declarator declaration-list[opt] compound-statement + /// decl-specs declarator declaration-list[opt] + /// compound-statement /// [C90] function-definition: [C99 6.7.1] - implicit int result - /// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement - /// [C++] function-definition: [C++ 8.4] + /// [C90] decl-specs[opt] declarator declaration-list[opt] + /// compound-statement [C++] function-definition: [C++ 8.4] /// decl-specifier-seq[opt] declarator ctor-initializer[opt] /// function-body /// [C++] function-definition: [C++ 8.4] @@ -1842,9 +1847,7 @@ class Parser : public CodeCompletionHandler { /// [C++] initializer: /// [C++] '=' initializer-clause /// [C++] '(' expression-list ')' - /// [C++0x] '=' 'default' [TODO] - /// [C++0x] '=' 'delete' - /// [C++0x] braced-init-list + /// [C++0x] '=' 'default' [TODO] [C++0x] '=' 'delete' [C++0x] braced-init-list /// \endverbatim /// /// According to the standard grammar, =default and =delete are function @@ -1961,9 +1964,11 @@ class Parser : public CodeCompletionHandler { /// enum-specifier: [C99 6.7.2.2] /// 'enum' identifier[opt] '{' enumerator-list '}' ///[C99/C++]'enum' identifier[opt] '{' enumerator-list ',' '}' - /// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt] + /// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' + /// [opt] /// '}' attributes[opt] - /// [MS] 'enum' __declspec[opt] identifier[opt] '{' enumerator-list ',' [opt] + /// [MS] 'enum' __declspec[opt] identifier[opt] '{' enumerator-list ',' + /// [opt] /// '}' /// 'enum' identifier /// [GNU] 'enum' attributes[opt] identifier @@ -1972,8 +1977,9 @@ class Parser : public CodeCompletionHandler { /// [C++11] enum-head '{' enumerator-list ',' '}' /// /// enum-head: [C++11] - /// enum-key attribute-specifier-seq[opt] identifier[opt] enum-base[opt] - /// enum-key attribute-specifier-seq[opt] nested-name-specifier + /// enum-key attribute-specifier-seq[opt] identifier[opt] + /// enum-base[opt] enum-key attribute-specifier-seq[opt] + /// nested-name-specifier /// identifier enum-base[opt] /// /// enum-key: [C++11] @@ -2454,8 +2460,8 @@ class Parser : public CodeCompletionHandler { /// Parse the contents of the "objc_bridge_related" attribute. /// \verbatim - /// objc_bridge_related '(' related_class ',' opt-class_method ',' opt-instance_method ')' - /// related_class: + /// objc_bridge_related '(' related_class ',' opt-class_method ',' + /// opt-instance_method ')' related_class: /// Identifier /// /// opt-class_method: @@ -2640,9 +2646,9 @@ class Parser : public CodeCompletionHandler { AR_CXX11AttributesParsed = 1 << 2, AR_DeclspecAttributesParsed = 1 << 3, AR_AllAttributesParsed = AR_GNUAttributesParsed | AR_CXX11AttributesParsed | - AR_DeclspecAttributesParsed, - AR_VendorAttributesParsed = - AR_GNUAttributesParsed | AR_DeclspecAttributesParsed + AR_DeclspecAttributesParsed, + AR_VendorAttributesParsed = AR_GNUAttributesParsed | + AR_DeclspecAttributesParsed }; /// ParseTypeQualifierListOpt @@ -3416,8 +3422,10 @@ class Parser : public CodeCompletionHandler { /// struct-or-union-specifier: [C99 6.7.2.1] /// struct-or-union identifier[opt] '{' struct-contents '}' /// struct-or-union identifier - /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents - /// '}' attributes[opt] + /// [GNU] struct-or-union attributes[opt] identifier[opt] '{' + /// struct-contents + /// '}' + /// attributes[opt] /// [GNU] struct-or-union attributes[opt] identifier /// struct-or-union: /// 'struct' @@ -3489,8 +3497,8 @@ class Parser : public CodeCompletionHandler { /// decl-specifier-seq[opt] member-declarator-list[opt] ';' /// function-definition ';'[opt] /// [C++26] friend-type-declaration - /// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO] - /// using-declaration [TODO] + /// ::[opt] nested-name-specifier template[opt] unqualified-id + /// ';'[TODO] using-declaration [TODO] /// [C++0x] static_assert-declaration /// template-declaration /// [GNU] '__extension__' member-declaration @@ -3956,8 +3964,9 @@ class Parser : public CodeCompletionHandler { /// [GNU] '__PRETTY_FUNCTION__' /// [GNU] '(' compound-statement ')' /// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')' - /// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')' - /// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ',' + /// [GNU] '__builtin_offsetof' '(' type-name ',' + /// offsetof-member-designator')' [GNU] '__builtin_choose_expr' '(' + /// assign-expr ',' assign-expr ',' /// assign-expr ')' /// [GNU] '__builtin_FILE' '(' ')' /// [CLANG] '__builtin_FILE_NAME' '(' ')' @@ -3973,21 +3982,19 @@ class Parser : public CodeCompletionHandler { /// [OBJC] '\@protocol' '(' identifier ')' /// [OBJC] '\@encode' '(' type-name ')' /// [OBJC] objc-string-literal - /// [C++] simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3] - /// [C++11] simple-type-specifier braced-init-list [C++11 5.2.3] - /// [C++] typename-specifier '(' expression-list[opt] ')' [C++ 5.2.3] - /// [C++11] typename-specifier braced-init-list [C++11 5.2.3] - /// [C++] 'const_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] - /// [C++] 'dynamic_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] - /// [C++] 'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] - /// [C++] 'static_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] - /// [C++] 'typeid' '(' expression ')' [C++ 5.2p1] - /// [C++] 'typeid' '(' type-id ')' [C++ 5.2p1] - /// [C++] 'this' [C++ 9.3.2] - /// [G++] unary-type-trait '(' type-id ')' - /// [G++] binary-type-trait '(' type-id ',' type-id ')' [TODO] - /// [EMBT] array-type-trait '(' type-id ',' integer ')' - /// [clang] '^' block-literal + /// [C++] simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3] + /// [C++11] simple-type-specifier braced-init-list [C++11 5.2.3] [C++] + /// typename-specifier '(' expression-list[opt] ')' [C++ 5.2.3] + /// [C++11] typename-specifier braced-init-list [C++11 5.2.3] [C++] + /// 'const_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] [C++] + /// 'dynamic_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] [C++] + /// 'reinterpret_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] [C++] + /// 'static_cast' '<' type-name '>' '(' expression ')' [C++ 5.2p1] [C++] + /// 'typeid' '(' expression ')' [C++ 5.2p1] [C++] + /// 'typeid' '(' type-id ')' [C++ 5.2p1] [C++] + /// 'this' [C++ 9.3.2] [G++] unary-type-trait '(' type-id ')' [G++] + /// binary-type-trait '(' type-id ',' type-id ')' [TODO] [EMBT] + /// array-type-trait '(' type-id ',' integer ')' [clang] '^' block-literal /// /// constant: [C99 6.4.4] /// integer-constant @@ -4153,8 +4160,9 @@ class Parser : public CodeCompletionHandler { /// \verbatim /// primary-expression: [C99 6.5.1] /// [GNU] '__builtin_va_arg' '(' assignment-expression ',' type-name ')' - /// [GNU] '__builtin_offsetof' '(' type-name ',' offsetof-member-designator')' - /// [GNU] '__builtin_choose_expr' '(' assign-expr ',' assign-expr ',' + /// [GNU] '__builtin_offsetof' '(' type-name ',' + /// offsetof-member-designator')' [GNU] '__builtin_choose_expr' '(' + /// assign-expr ',' assign-expr ',' /// assign-expr ')' /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' /// [GNU] '__builtin_FILE' '(' ')' @@ -4886,16 +4894,8 @@ class Parser : public CodeCompletionHandler { /// \verbatim /// simple-type-specifier: /// '::'[opt] nested-name-specifier[opt] type-name - /// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO] - /// char - /// wchar_t - /// bool - /// short - /// int - /// long - /// signed - /// unsigned - /// float + /// '::'[opt] nested-name-specifier 'template' simple-template-id + /// [TODO] char wchar_t bool short int long signed unsigned float /// double /// void /// [GNU] typeof-specifier @@ -5563,7 +5563,8 @@ class Parser : public CodeCompletionHandler { /// '<' objc-type-parameter (',' objc-type-parameter)* '>' /// /// objc-type-parameter: - /// objc-type-parameter-variance? identifier objc-type-parameter-bound[opt] + /// objc-type-parameter-variance? identifier + /// objc-type-parameter-bound[opt] /// /// objc-type-parameter-bound: /// ':' type-name @@ -5834,8 +5835,8 @@ class Parser : public CodeCompletionHandler { /// objc-keyword-selector objc-keyword-decl /// /// objc-keyword-decl: - /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier - /// objc-selector ':' objc-keyword-attributes[opt] identifier + /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] + /// identifier objc-selector ':' objc-keyword-attributes[opt] identifier /// ':' objc-type-name objc-keyword-attributes[opt] identifier /// ':' objc-keyword-attributes[opt] identifier /// @@ -5909,7 +5910,8 @@ class Parser : public CodeCompletionHandler { /// \verbatim /// objc-scalar-literal : '@' scalar-literal /// ; - /// scalar-literal : | numeric-constant /* any numeric constant. */ + /// scalar-literal : | numeric-constant /* any numeric + /// constant. */ /// ; /// \endverbatim ExprResult ParseObjCNumericLiteral(SourceLocation AtLoc); @@ -6053,11 +6055,13 @@ class Parser : public CodeCompletionHandler { /// \verbatim /// objc-try-catch-statement: /// @try compound-statement objc-catch-list[opt] - /// @try compound-statement objc-catch-list[opt] @finally compound-statement + /// @try compound-statement objc-catch-list[opt] @finally + /// compound-statement /// /// objc-catch-list: /// @catch ( parameter-declaration ) compound-statement - /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement + /// objc-catch-list @catch ( catch-parameter-declaration ) + /// compound-statement /// catch-parameter-declaration: /// parameter-declaration /// '...' [OBJC2] @@ -6454,7 +6458,8 @@ class Parser : public CodeCompletionHandler { /// Parses an OpenMP context selector set. /// /// \verbatim - /// <trait-set-selector-name> '=' '{' <trait-selector> [, <trait-selector>]* '}' + /// <trait-set-selector-name> '=' '{' <trait-selector> [, <trait-selector>]* + /// '}' /// \endverbatim void parseOMPContextSelectorSet(OMPTraitSet &TISet, llvm::StringMap<SourceLocation> &SeenSets); @@ -6559,8 +6564,8 @@ class Parser : public CodeCompletionHandler { /// annot_pragma_openmp_end /// /// declare-mapper-directive: - /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] - /// <type> <var> ')' [<clause>[[,] <clause>] ... ] + /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> + /// ':'] <type> <var> ')' [<clause>[[,] <clause>] ... ] /// annot_pragma_openmp_end /// /// declare-simd-directive: @@ -6592,8 +6597,8 @@ class Parser : public CodeCompletionHandler { /// declare-reduction-directive: /// annot_pragma_openmp 'declare' 'reduction' /// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')' - /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')'] - /// annot_pragma_openmp_end + /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> + /// ')'] annot_pragma_openmp_end /// \endverbatim /// <reduction_id> is either a base language identifier or one of the /// following operators: '+', '-', '*', '&', '|', '^', '&&' and '||'. @@ -6608,8 +6613,8 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// declare-mapper-directive: - /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifier> ':'] - /// <type> <var> ')' [<clause>[[,] <clause>] ... ] + /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifier> + /// ':'] <type> <var> ')' [<clause>[[,] <clause>] ... ] /// annot_pragma_openmp_end /// \endverbatim /// <mapper-identifier> and <var> are base language identifiers. @@ -6657,8 +6662,8 @@ class Parser : public CodeCompletionHandler { /// annot_pragma_openmp_end /// /// declare-mapper-directive: - /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] - /// <type> <var> ')' [<clause>[[,] <clause>] ... ] + /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> + /// ':'] <type> <var> ')' [<clause>[[,] <clause>] ... ] /// annot_pragma_openmp_end /// /// executable-directive: @@ -6831,7 +6836,8 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// schedule-clause: - /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] + /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression + /// ] /// ')' /// /// if-clause: @@ -7015,7 +7021,8 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// init-clause: - /// init([interop-modifier, ]interop-type[[, interop-type] ... ]:interop-var) + /// init([interop-modifier, ]interop-type[[, interop-type] ... + /// ]:interop-var) /// /// destroy-clause: /// destroy(interop-var) @@ -7069,10 +7076,10 @@ class Parser : public CodeCompletionHandler { bool parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy &Data); /// Parse map-type-modifiers in map clause. - /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] list) - /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) | - /// present - /// where, map-type ::= alloc | delete | from | release | to | tofrom + /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] [map-type] : ] + /// list) where, map-type-modifier ::= always | close | + /// mapper(mapper-identifier) | present where, map-type ::= alloc | delete | + /// from | release | to | tofrom bool parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data); /// Parses 'omp begin declare variant' directive. @@ -7294,8 +7301,7 @@ class Parser : public CodeCompletionHandler { /// MisleadingIndentationChecker on an else active, this location is invalid. SourceLocation MisleadingIndentationElseLoc; - private: - +private: /// Flags describing a context in which we're parsing a statement. enum class ParsedStmtContext { /// This context permits declarations in language modes where declarations @@ -7538,9 +7544,8 @@ class Parser : public CodeCompletionHandler { /// for-statement: [C99 6.8.5.3] /// 'for' '(' expr[opt] ';' expr[opt] ';' expr[opt] ')' statement /// 'for' '(' declaration expr[opt] ';' expr[opt] ')' statement - /// [C++] 'for' '(' for-init-statement condition[opt] ';' expression[opt] ')' - /// [C++] statement - /// [C++0x] 'for' + /// [C++] 'for' '(' for-init-statement condition[opt] ';' expression[opt] + /// ')' [C++] statement [C++0x] 'for' /// 'co_await'[opt] [Coroutines] /// '(' for-range-declaration ':' for-range-initializer ')' /// statement @@ -7685,7 +7690,8 @@ class Parser : public CodeCompletionHandler { /// /// exception-declaration: /// attribute-specifier-seq[opt] type-specifier-seq declarator - /// attribute-specifier-seq[opt] type-specifier-seq abstract-declarator[opt] + /// attribute-specifier-seq[opt] type-specifier-seq + /// abstract-declarator[opt] /// '...' /// \endverbatim /// @@ -8156,7 +8162,8 @@ class Parser : public CodeCompletionHandler { /// /// \verbatim /// template-declaration: [C++ temp] - /// 'export'[opt] 'template' '<' template-parameter-list '>' declaration + /// 'export'[opt] 'template' '<' template-parameter-list '>' + /// declaration /// /// template-declaration: [C++2a] /// template-head declaration @@ -8953,7 +8960,7 @@ class Parser : public CodeCompletionHandler { /// ptr-operator: /// '*' cv-qualifier-seq[opt] /// '&' - /// [C++0x] '&&' [TODO] + /// [C++0x] '&&' [TODO] /// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] /// /// cv-qualifier-seq: @@ -8968,16 +8975,15 @@ class Parser : public CodeCompletionHandler { /// /// id-expression: /// unqualified-id - /// qualified-id [TODO] + /// qualified-id [TODO] /// /// unqualified-id: /// identifier /// operator-function-id /// conversion-function-id /// literal-operator-id - /// '~' class-name [TODO] - /// '~' decltype-specifier [TODO] - /// template-id [TODO] + /// '~' class-name [TODO] + /// '~' decltype-specifier [TODO] template-id [TODO] /// \endverbatim /// TPResult TryParseDeclarator(bool mayBeAbstract, bool mayHaveIdentifier = true, @@ -8994,8 +9000,9 @@ class Parser : public CodeCompletionHandler { /// parameter-declaration-list ',' parameter-declaration /// /// parameter-declaration: - /// attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt] - /// attribute-specifier-seq[opt] decl-specifier-seq declarator attributes[opt] + /// attribute-specifier-seq[opt] decl-specifier-seq declarator + /// attributes[opt] attribute-specifier-seq[opt] decl-specifier-seq + /// declarator attributes[opt] /// '=' assignment-expression /// attribute-specifier-seq[opt] decl-specifier-seq abstract-declarator[opt] /// attributes[opt] diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index d701cbaa43bdd..fe31725325152 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -891,8 +891,9 @@ Decl *Parser::ParseAliasDeclarationAfterDeclarator( Decl *DeclFromDeclSpec = nullptr; TypeResult TypeAlias = ParseTypeName(nullptr, - TemplateInfo.Kind != ParsedTemplateKind::NonTemplate ? DeclaratorContext::AliasTemplate - : DeclaratorContext::AliasDecl, + TemplateInfo.Kind != ParsedTemplateKind::NonTemplate + ? DeclaratorContext::AliasTemplate + : DeclaratorContext::AliasDecl, AS, &DeclFromDeclSpec, &Attrs); if (OwnedType) *OwnedType = DeclFromDeclSpec; @@ -1687,63 +1688,31 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, Tok.isOneOf( #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) tok::kw___##Trait, #include "clang/Basic/BuiltinTraits.inc" - tok::kw___is_abstract, - tok::kw___is_aggregate, - tok::kw___is_arithmetic, - tok::kw___is_array, - tok::kw___is_assignable, - tok::kw___is_base_of, - tok::kw___is_bounded_array, - tok::kw___is_class, - tok::kw___is_complete_type, - tok::kw___is_compound, - tok::kw___is_const, - tok::kw___is_constructible, - tok::kw___is_convertible, - tok::kw___is_convertible_to, - tok::kw___is_destructible, - tok::kw___is_empty, - tok::kw___is_enum, - tok::kw___is_floating_point, - tok::kw___is_final, - tok::kw___is_function, - tok::kw___is_fundamental, - tok::kw___is_integral, - tok::kw___is_interface_class, - tok::kw___is_literal, - tok::kw___is_lvalue_expr, - tok::kw___is_lvalue_reference, - tok::kw___is_member_function_pointer, - tok::kw___is_member_object_pointer, - tok::kw___is_member_pointer, - tok::kw___is_nothrow_assignable, - tok::kw___is_nothrow_constructible, - tok::kw___is_nothrow_convertible, - tok::kw___is_nothrow_destructible, - tok::kw___is_object, - tok::kw___is_pod, - tok::kw___is_pointer, - tok::kw___is_polymorphic, - tok::kw___is_reference, - tok::kw___is_rvalue_expr, - tok::kw___is_rvalue_reference, - tok::kw___is_same, - tok::kw___is_scalar, - tok::kw___is_scoped_enum, - tok::kw___is_sealed, - tok::kw___is_signed, - tok::kw___is_standard_layout, - tok::kw___is_trivial, + tok::kw___is_abstract, tok::kw___is_aggregate, + tok::kw___is_arithmetic, tok::kw___is_array, tok::kw___is_assignable, + tok::kw___is_base_of, tok::kw___is_bounded_array, tok::kw___is_class, + tok::kw___is_complete_type, tok::kw___is_compound, tok::kw___is_const, + tok::kw___is_constructible, tok::kw___is_convertible, + tok::kw___is_convertible_to, tok::kw___is_destructible, + tok::kw___is_empty, tok::kw___is_enum, tok::kw___is_floating_point, + tok::kw___is_final, tok::kw___is_function, tok::kw___is_fundamental, + tok::kw___is_integral, tok::kw___is_interface_class, + tok::kw___is_literal, tok::kw___is_lvalue_expr, + tok::kw___is_lvalue_reference, tok::kw___is_member_function_pointer, + tok::kw___is_member_object_pointer, tok::kw___is_member_pointer, + tok::kw___is_nothrow_assignable, tok::kw___is_nothrow_constructible, + tok::kw___is_nothrow_convertible, tok::kw___is_nothrow_destructible, + tok::kw___is_object, tok::kw___is_pod, tok::kw___is_pointer, + tok::kw___is_polymorphic, tok::kw___is_reference, + tok::kw___is_rvalue_expr, tok::kw___is_rvalue_reference, + tok::kw___is_same, tok::kw___is_scalar, tok::kw___is_scoped_enum, + tok::kw___is_sealed, tok::kw___is_signed, + tok::kw___is_standard_layout, tok::kw___is_trivial, tok::kw___is_trivially_equality_comparable, tok::kw___is_trivially_assignable, - tok::kw___is_trivially_constructible, - tok::kw___is_trivially_copyable, - tok::kw___is_unbounded_array, - tok::kw___is_union, - tok::kw___is_unsigned, - tok::kw___is_void, - tok::kw___is_volatile - )) + tok::kw___is_trivially_constructible, tok::kw___is_trivially_copyable, + tok::kw___is_unbounded_array, tok::kw___is_union, + tok::kw___is_unsigned, tok::kw___is_void, tok::kw___is_volatile)) // GNU libstdc++ 4.2 and libc++ use certain intrinsic names as the // name of struct templates, but some are keywords in GCC >= 4.3 // and Clang. Therefore, when we see the token sequence "struct @@ -2316,7 +2285,8 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // C, since definitions are not permitted in this context in C++. if (TUK == TagUseKind::Definition && (getLangOpts().CPlusPlus || !isTypeSpecifier(DSC)) && - (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate || !isValidAfterTypeSpecifier(false))) { + (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate || + !isValidAfterTypeSpecifier(false))) { if (Tok.isNot(tok::semi)) { const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); ExpectAndConsume(tok::semi, diag::err_expected_after, @@ -4581,7 +4551,10 @@ bool Parser::ParseCXX11AttributeArgs( ScopeName, AttrName, getTargetInfo(), getLangOpts())) { // Eat the left paren, then skip to the ending right paren. ConsumeParen(); - SkipUntil(tok::r_paren); + if (!SkipUntil(tok::r_paren, StopAtUnbalanced)) { + Diag(Tok, diag::err_expected) << tok::r_paren; + SkipUntil(tok::r_paren, StopAtSemi); + } return false; } diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 84059a41238cc..1b78f9e867035 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -31,7 +31,6 @@ #include "llvm/Support/TimeProfiler.h" using namespace clang; - namespace { /// A comment handler that passes comments found by the preprocessor /// to the parser action. @@ -39,7 +38,7 @@ class ActionCommentHandler : public CommentHandler { Sema &S; public: - explicit ActionCommentHandler(Sema &S) : S(S) { } + explicit ActionCommentHandler(Sema &S) : S(S) {} bool HandleComment(Preprocessor &PP, SourceRange Comment) override { S.ActOnComment(Comment); @@ -112,16 +111,16 @@ void Parser::SuggestParentheses(SourceLocation Loc, unsigned DK, return; } - Diag(Loc, DK) - << FixItHint::CreateInsertion(ParenRange.getBegin(), "(") - << FixItHint::CreateInsertion(EndLoc, ")"); + Diag(Loc, DK) << FixItHint::CreateInsertion(ParenRange.getBegin(), "(") + << FixItHint::CreateInsertion(EndLoc, ")"); } static bool IsCommonTypo(tok::TokenKind ExpectedTok, const Token &Tok) { switch (ExpectedTok) { case tok::semi: return Tok.is(tok::colon) || Tok.is(tok::comma); // : or , for ; - default: return false; + default: + return false; } } @@ -138,7 +137,7 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID, { DiagnosticBuilder DB = Diag(Loc, DiagID); DB << FixItHint::CreateReplacement( - SourceRange(Loc), tok::getPunctuatorSpelling(ExpectedTok)); + SourceRange(Loc), tok::getPunctuatorSpelling(ExpectedTok)); if (DiagID == diag::err_expected) DB << ExpectedTok; else if (DiagID == diag::err_expected_after) @@ -183,14 +182,13 @@ bool Parser::ExpectAndConsumeSemi(unsigned DiagID, StringRef TokenUsed) { if ((Tok.is(tok::r_paren) || Tok.is(tok::r_square)) && NextToken().is(tok::semi)) { Diag(Tok, diag::err_extraneous_token_before_semi) - << PP.getSpelling(Tok) - << FixItHint::CreateRemoval(Tok.getLocation()); + << PP.getSpelling(Tok) << FixItHint::CreateRemoval(Tok.getLocation()); ConsumeAnyToken(); // The ')' or ']'. - ConsumeToken(); // The ';'. + ConsumeToken(); // The ';'. return false; } - return ExpectAndConsume(tok::semi, DiagID , TokenUsed); + return ExpectAndConsume(tok::semi, DiagID, TokenUsed); } bool Parser::isLikelyAtStartOfNewDeclaration() { @@ -199,7 +197,8 @@ bool Parser::isLikelyAtStartOfNewDeclaration() { } void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) { - if (!Tok.is(tok::semi)) return; + if (!Tok.is(tok::semi)) + return; bool HadMultipleSemis = false; SourceLocation StartLoc = Tok.getLocation(); @@ -233,7 +232,7 @@ void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) { else // A single semicolon is valid after a member function definition. Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def) - << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); + << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc)); } bool Parser::expectIdentifier() { @@ -393,17 +392,23 @@ bool Parser::SkipUntil(ArrayRef<tok::TokenKind> Toks, SkipUntilFlags Flags) { // and return it. Otherwise, this is a spurious RHS token, which we skip. case tok::r_paren: if (ParenCount && !isFirstTokenSkipped) - return false; // Matches something. + return false; // Matches something. + if (HasFlagsSet(Flags, StopAtUnbalanced)) + return false; ConsumeParen(); break; case tok::r_square: if (BracketCount && !isFirstTokenSkipped) - return false; // Matches something. + return false; // Matches something. + if (HasFlagsSet(Flags, StopAtUnbalanced)) + return false; ConsumeBracket(); break; case tok::r_brace: if (BraceCount && !isFirstTokenSkipped) - return false; // Matches something. + return false; // Matches something. + if (HasFlagsSet(Flags, StopAtUnbalanced)) + return false; ConsumeBrace(); break; @@ -451,8 +456,8 @@ void Parser::ExitScope() { } Parser::ParseScopeFlags::ParseScopeFlags(Parser *Self, unsigned ScopeFlags, - bool ManageFlags) - : CurScope(ManageFlags ? Self->getCurScope() : nullptr) { + bool ManageFlags) + : CurScope(ManageFlags ? Self->getCurScope() : nullptr) { if (CurScope) { OldFlags = CurScope->getFlags(); CurScope->setFlags(ScopeFlags); @@ -464,7 +469,6 @@ Parser::ParseScopeFlags::~ParseScopeFlags() { CurScope->setFlags(OldFlags); } - //===----------------------------------------------------------------------===// // C99 6.9: External Definitions. //===----------------------------------------------------------------------===// @@ -555,26 +559,30 @@ void Parser::Initialize() { Ident_GetExceptionCode = Ident_GetExceptionInfo = nullptr; Ident_AbnormalTermination = nullptr; - if(getLangOpts().Borland) { - Ident__exception_info = PP.getIdentifierInfo("_exception_info"); - Ident___exception_info = PP.getIdentifierInfo("__exception_info"); - Ident_GetExceptionInfo = PP.getIdentifierInfo("GetExceptionInformation"); - Ident__exception_code = PP.getIdentifierInfo("_exception_code"); - Ident___exception_code = PP.getIdentifierInfo("__exception_code"); - Ident_GetExceptionCode = PP.getIdentifierInfo("GetExceptionCode"); - Ident__abnormal_termination = PP.getIdentifierInfo("_abnormal_termination"); - Ident___abnormal_termination = PP.getIdentifierInfo("__abnormal_termination"); - Ident_AbnormalTermination = PP.getIdentifierInfo("AbnormalTermination"); - - PP.SetPoisonReason(Ident__exception_code,diag::err_seh___except_block); - PP.SetPoisonReason(Ident___exception_code,diag::err_seh___except_block); - PP.SetPoisonReason(Ident_GetExceptionCode,diag::err_seh___except_block); - PP.SetPoisonReason(Ident__exception_info,diag::err_seh___except_filter); - PP.SetPoisonReason(Ident___exception_info,diag::err_seh___except_filter); - PP.SetPoisonReason(Ident_GetExceptionInfo,diag::err_seh___except_filter); - PP.SetPoisonReason(Ident__abnormal_termination,diag::err_seh___finally_block); - PP.SetPoisonReason(Ident___abnormal_termination,diag::err_seh___finally_block); - PP.SetPoisonReason(Ident_AbnormalTermination,diag::err_seh___finally_block); + if (getLangOpts().Borland) { + Ident__exception_info = PP.getIdentifierInfo("_exception_info"); + Ident___exception_info = PP.getIdentifierInfo("__exception_info"); + Ident_GetExceptionInfo = PP.getIdentifierInfo("GetExceptionInformation"); + Ident__exception_code = PP.getIdentifierInfo("_exception_code"); + Ident___exception_code = PP.getIdentifierInfo("__exception_code"); + Ident_GetExceptionCode = PP.getIdentifierInfo("GetExceptionCode"); + Ident__abnormal_termination = PP.getIdentifierInfo("_abnormal_termination"); + Ident___abnormal_termination = + PP.getIdentifierInfo("__abnormal_termination"); + Ident_AbnormalTermination = PP.getIdentifierInfo("AbnormalTermination"); + + PP.SetPoisonReason(Ident__exception_code, diag::err_seh___except_block); + PP.SetPoisonReason(Ident___exception_code, diag::err_seh___except_block); + PP.SetPoisonReason(Ident_GetExceptionCode, diag::err_seh___except_block); + PP.SetPoisonReason(Ident__exception_info, diag::err_seh___except_filter); + PP.SetPoisonReason(Ident___exception_info, diag::err_seh___except_filter); + PP.SetPoisonReason(Ident_GetExceptionInfo, diag::err_seh___except_filter); + PP.SetPoisonReason(Ident__abnormal_termination, + diag::err_seh___finally_block); + PP.SetPoisonReason(Ident___abnormal_termination, + diag::err_seh___finally_block); + PP.SetPoisonReason(Ident_AbnormalTermination, + diag::err_seh___finally_block); } Actions.Initialize(); @@ -637,11 +645,12 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, return false; case tok::kw_import: - import_decl: { - Decl *ImportDecl = ParseModuleImport(SourceLocation(), ImportState); - Result = Actions.ConvertDeclToDeclGroup(ImportDecl); - return false; - } + import_decl: + { + Decl *ImportDecl = ParseModuleImport(SourceLocation(), ImportState); + Result = Actions.ConvertDeclToDeclGroup(ImportDecl); + return false; + } case tok::annot_module_include: { auto Loc = Tok.getLocation(); @@ -691,7 +700,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result, // Late template parsing can begin. Actions.SetLateTemplateParser(LateTemplateParserCallback, this); Actions.ActOnEndOfTranslationUnit(); - //else don't tell Sema that we ended parsing: more input might come. + // else don't tell Sema that we ended parsing: more input might come. return true; default: break; @@ -825,7 +834,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs, return nullptr; case tok::kw___extension__: { // __extension__ silences extension warnings in the subexpression. - ExtensionRAIIObject O(Diags); // Use RAII to do this. + ExtensionRAIIObject O(Diags); // Use RAII to do this. ConsumeToken(); return ParseExternalDeclaration(Attrs, DeclSpecAttrs); } @@ -930,8 +939,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs, // Parse (then ignore) 'static' prior to a template instantiation. This is // a GCC extension that we intentionally do not support. if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) { - Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored) - << 0; + Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored) << 0; SourceLocation DeclEnd; return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs, DeclSpecAttrs); @@ -953,7 +961,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs, // a GCC extension that we intentionally do not support. if (NextKind == tok::kw_template) { Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored) - << 1; + << 1; SourceLocation DeclEnd; return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs, DeclSpecAttrs); @@ -968,9 +976,10 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs, // Extern templates SourceLocation ExternLoc = ConsumeToken(); SourceLocation TemplateLoc = ConsumeToken(); - Diag(ExternLoc, getLangOpts().CPlusPlus11 ? - diag::warn_cxx98_compat_extern_template : - diag::ext_extern_template) << SourceRange(ExternLoc, TemplateLoc); + Diag(ExternLoc, getLangOpts().CPlusPlus11 + ? diag::warn_cxx98_compat_extern_template + : diag::ext_extern_template) + << SourceRange(ExternLoc, TemplateLoc); SourceLocation DeclEnd; return ParseExplicitInstantiation(DeclaratorContext::File, ExternLoc, TemplateLoc, DeclEnd, Attrs); @@ -1015,18 +1024,19 @@ bool Parser::isDeclarationAfterDeclarator() { return false; } - return Tok.is(tok::equal) || // int X()= -> not a function def - Tok.is(tok::comma) || // int X(), -> not a function def - Tok.is(tok::semi) || // int X(); -> not a function def - Tok.is(tok::kw_asm) || // int X() __asm__ -> not a function def - Tok.is(tok::kw___attribute) || // int X() __attr__ -> not a function def - (getLangOpts().CPlusPlus && - Tok.is(tok::l_paren)); // int X(0) -> not a function def [C++] + return Tok.is(tok::equal) || // int X()= -> not a function def + Tok.is(tok::comma) || // int X(), -> not a function def + Tok.is(tok::semi) || // int X(); -> not a function def + Tok.is(tok::kw_asm) || // int X() __asm__ -> not a function def + Tok.is( + tok::kw___attribute) || // int X() __attr__ -> not a function def + (getLangOpts().CPlusPlus && + Tok.is(tok::l_paren)); // int X(0) -> not a function def [C++] } bool Parser::isStartOfFunctionDefinition(const ParsingDeclarator &Declarator) { assert(Declarator.isFunctionDeclarator() && "Isn't a function declarator"); - if (Tok.is(tok::l_brace)) // int X() {} + if (Tok.is(tok::l_brace)) // int X() {} return true; // Handle K&R C argument lists: int X(f) int f; {} @@ -1039,8 +1049,8 @@ bool Parser::isStartOfFunctionDefinition(const ParsingDeclarator &Declarator) { return KW.is(tok::kw_default) || KW.is(tok::kw_delete); } - return Tok.is(tok::colon) || // X() : Base() {} (used for ctors) - Tok.is(tok::kw_try); // X() try { ... } + return Tok.is(tok::colon) || // X() : Base() {} (used for ctors) + Tok.is(tok::kw_try); // X() try { ... } } Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( @@ -1097,7 +1107,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( DS.complete(TheDecl); Actions.ActOnDefinedDeclarationSpecifier(TheDecl); if (AnonRecord) { - Decl* decls[] = {AnonRecord, TheDecl}; + Decl *decls[] = {AnonRecord, TheDecl}; return Actions.BuildDeclaratorGroup(decls); } return Actions.ConvertDeclToDeclGroup(TheDecl); @@ -1135,7 +1145,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( return ParseObjCAtImplementationDeclaration(AtLoc, DS.getAttributes()); return Actions.ConvertDeclToDeclGroup( - ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes())); + ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes())); } // If the declspec consisted only of 'extern' and we have a string @@ -1197,10 +1207,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const char *PrevSpec; unsigned DiagID; const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); - D.getMutableDeclSpec().SetTypeSpecType(DeclSpec::TST_int, - D.getIdentifierLoc(), - PrevSpec, DiagID, - Policy); + D.getMutableDeclSpec().SetTypeSpecType( + DeclSpec::TST_int, D.getIdentifierLoc(), PrevSpec, DiagID, Policy); D.SetRangeBegin(D.getDeclSpec().getSourceRange().getBegin()); } @@ -1246,8 +1254,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, Scope *ParentScope = getCurScope()->getParent(); D.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); - Decl *DP = Actions.HandleDeclarator(ParentScope, D, - TemplateParameterLists); + Decl *DP = Actions.HandleDeclarator(ParentScope, D, TemplateParameterLists); D.complete(DP); D.getMutableDeclSpec().abort(); @@ -1275,8 +1282,8 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, Scope *ParentScope = getCurScope()->getParent(); D.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); - Decl *FuncDecl = Actions.HandleDeclarator(ParentScope, D, - MultiTemplateParamsArg()); + Decl *FuncDecl = + Actions.HandleDeclarator(ParentScope, D, MultiTemplateParamsArg()); D.complete(FuncDecl); D.getMutableDeclSpec().abort(); if (FuncDecl) { @@ -1445,7 +1452,8 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Enter function-declaration scope, limiting any declarators to the // function prototype scope, including parameter declarators. ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | - Scope::FunctionDeclarationScope | Scope::DeclScope); + Scope::FunctionDeclarationScope | + Scope::DeclScope); // Read all the argument declarations. while (isDeclarationSpecifier(ImplicitTypenameContext::No)) { @@ -1491,8 +1499,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { MaybeParseGNUAttributes(ParmDeclarator); // Ask the actions module to compute the type for this declarator. - Decl *Param = - Actions.ActOnParamDeclarator(getCurScope(), ParmDeclarator); + Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDeclarator); if (Param && // A missing identifier has already been diagnosed. @@ -1500,12 +1507,12 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Scan the argument list looking for the correct param to apply this // type. - for (unsigned i = 0; ; ++i) { + for (unsigned i = 0;; ++i) { // C99 6.9.1p6: those declarators shall declare only identifiers from // the identifier list. if (i == FTI.NumParams) { Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param) - << ParmDeclarator.getIdentifier(); + << ParmDeclarator.getIdentifier(); break; } @@ -1514,7 +1521,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { if (FTI.Params[i].Param) { Diag(ParmDeclarator.getIdentifierLoc(), diag::err_param_redefinition) - << ParmDeclarator.getIdentifier(); + << ParmDeclarator.getIdentifier(); } else { FTI.Params[i].Param = Param; } @@ -1627,8 +1634,8 @@ ExprResult Parser::ParseSimpleAsm(bool ForAsmLabel, SourceLocation *EndLoc) { TemplateIdAnnotation *Parser::takeTemplateIdAnnotation(const Token &tok) { assert(tok.is(tok::annot_template_id) && "Expected template-id token"); - TemplateIdAnnotation * - Id = static_cast<TemplateIdAnnotation *>(tok.getAnnotationValue()); + TemplateIdAnnotation *Id = + static_cast<TemplateIdAnnotation *>(tok.getAnnotationValue()); return Id; } @@ -1747,10 +1754,9 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC, // Consume the name. SourceLocation IdentifierLoc = ConsumeToken(); SourceLocation NewEndLoc; - TypeResult NewType - = parseObjCTypeArgsAndProtocolQualifiers(IdentifierLoc, Ty, - /*consumeLastToken=*/false, - NewEndLoc); + TypeResult NewType = parseObjCTypeArgsAndProtocolQualifiers( + IdentifierLoc, Ty, + /*consumeLastToken=*/false, NewEndLoc); if (NewType.isUsable()) Ty = NewType.get(); else if (Tok.is(tok::eof)) // Nothing to do here, bail out... @@ -1859,8 +1865,7 @@ bool Parser::TryKeywordIdentFallback(bool DisableKeyword) { } Diag(Tok, diag::ext_keyword_as_ident) - << PP.getSpelling(Tok) - << DisableKeyword; + << PP.getSpelling(Tok) << DisableKeyword; if (DisableKeyword) II->revertTokenIDToIdentifier(); Tok.setKind(tok::identifier); @@ -1950,7 +1955,7 @@ bool Parser::TryAnnotateTypeOrScopeToken( TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); if (!TemplateId->mightBeType()) { Diag(Tok, diag::err_typename_refers_to_non_type_template) - << Tok.getAnnotationRange(); + << Tok.getAnnotationRange(); return true; } @@ -1965,8 +1970,7 @@ bool Parser::TryAnnotateTypeOrScopeToken( TemplateId->TemplateNameLoc, TemplateId->LAngleLoc, TemplateArgsPtr, TemplateId->RAngleLoc); } else { - Diag(Tok, diag::err_expected_type_name_after_typename) - << SS.getRange(); + Diag(Tok, diag::err_expected_type_name_after_typename) << SS.getRange(); return true; } @@ -2019,10 +2023,9 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec( // Consume the name. SourceLocation IdentifierLoc = ConsumeToken(); SourceLocation NewEndLoc; - TypeResult NewType - = parseObjCTypeArgsAndProtocolQualifiers(IdentifierLoc, Ty, - /*consumeLastToken=*/false, - NewEndLoc); + TypeResult NewType = parseObjCTypeArgsAndProtocolQualifiers( + IdentifierLoc, Ty, + /*consumeLastToken=*/false, NewEndLoc); if (NewType.isUsable()) Ty = NewType.get(); else if (Tok.is(tok::eof)) // Nothing to do here, bail out... @@ -2060,7 +2063,7 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec( if (TemplateNameKind TNK = Actions.isTemplateName( getCurScope(), SS, /*hasTemplateKeyword=*/false, TemplateName, - /*ObjectType=*/nullptr, /*EnteringContext*/false, Template, + /*ObjectType=*/nullptr, /*EnteringContext*/ false, Template, MemberOfUnknownSpecialization)) { // Only annotate an undeclared template name as a template-id if the // following tokens have the form of a template argument list. @@ -2222,7 +2225,7 @@ void Parser::CodeCompleteModuleImport(SourceLocation ImportLoc, Actions.CodeCompletion().CodeCompleteModuleImport(ImportLoc, Path); } -bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) { +bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition &Result) { assert((Tok.is(tok::kw___if_exists) || Tok.is(tok::kw___if_not_exists)) && "Expected '__if_exists' or '__if_not_exists'"); Result.IsIfExists = Tok.is(tok::kw___if_exists); @@ -2231,7 +2234,7 @@ bool Parser::ParseMicrosoftIfExistsCondition(IfExistsCondition& Result) { BalancedDelimiterTracker T(*this, tok::l_paren); if (T.consumeOpen()) { Diag(Tok, diag::err_expected_lparen_after) - << (Result.IsIfExists? "__if_exists" : "__if_not_exists"); + << (Result.IsIfExists ? "__if_exists" : "__if_not_exists"); return true; } @@ -2352,7 +2355,7 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) { } if (MDK == Sema::ModuleDeclKind::Interface) { Diag(StartLoc, diag::err_module_fragment_exported) - << /*global*/0 << FixItHint::CreateRemoval(StartLoc); + << /*global*/ 0 << FixItHint::CreateRemoval(StartLoc); } ImportState = Sema::ModuleImportState::GlobalFragment; return Actions.ActOnGlobalModuleFragmentDecl(ModuleLoc); @@ -2363,7 +2366,7 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) { NextToken().is(tok::kw_private)) { if (MDK == Sema::ModuleDeclKind::Interface) { Diag(StartLoc, diag::err_module_fragment_exported) - << /*private*/1 << FixItHint::CreateRemoval(StartLoc); + << /*private*/ 1 << FixItHint::CreateRemoval(StartLoc); } ConsumeToken(); SourceLocation PrivateLoc = ConsumeToken(); @@ -2634,7 +2637,7 @@ void Parser::diagnoseUseOfC11Keyword(const Token &Tok) { bool BalancedDelimiterTracker::diagnoseOverflow() { P.Diag(P.Tok, diag::err_bracket_depth_exceeded) - << P.getLangOpts().BracketDepth; + << P.getLangOpts().BracketDepth; P.Diag(P.Tok, diag::note_bracket_depth); P.cutOffParsing(); return true; diff --git a/clang/test/Parser/cxx11-unbalanced-attr-args.cpp b/clang/test/Parser/cxx11-unbalanced-attr-args.cpp new file mode 100644 index 0000000000000..ba132bca19c72 --- /dev/null +++ b/clang/test/Parser/cxx11-unbalanced-attr-args.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -x c -std=c23 %s + +[[X1(])]]; // expected-error {{expected ')'}} expected-warning {{unknown attribute 'X1' ignored}} +[[X1(})]]; // expected-error {{expected ')'}} expected-warning {{unknown attribute 'X1' ignored}} +[[X1]]; // expected-warning {{unknown attribute 'X1' ignored}} +[[X1()]]; // expected-warning {{unknown attribute 'X1' ignored}} \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
