aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseTemplate.cpp
AgeCommit message (Collapse)AuthorFilesLines
30 hours[Clang] Add the template depth when parsing type constraints (#163960)Younan Zhang1-0/+6
The lambdas can introduce new template parameters, and things would go wrong if the new template parameters still lived in the depth of the parent, when we evaluate the type constraints. Fixes https://github.com/llvm/llvm-project/issues/162092
9 days[Sema] Keep attribute lists in the order the attributes were parsed (#162714)Henrik G. Olsson1-1/+1
This renames some attribute list related functions, to make callers think about whether they want to append or prepend to the list, instead of defaulting to prepending which is often not the desired behaviour (for the cases where it matters, sometimes we're just adding to an empty list). Then it adjusts some of these calls to append where they were previously prepending. This has the effect of making `err_attributes_are_not_compatible` consistent in emitting diagnostics as `<new-attr> and <existing-attr> are not compatible`, regardless of the syntax used to apply the attributes.
2025-08-20[Clang] Add a builtin that deduplicate types into a pack (#106730)Ilya Biryukov1-0/+2
The new builtin `__builtin_dedup_pack` removes duplicates from list of types. The added builtin is special in that they produce an unexpanded pack in the spirit of P3115R0 proposal. Produced packs can be used directly in template argument lists and get immediately expanded as soon as results of the computation are available. It allows to easily combine them, e.g.: ```cpp template <class ...T> struct Normalize { // Note: sort is not included in this PR, it illustrates the idea. using result = std::tuple< __builtin_sort_pack< __builtin_dedup_pack<int, double, T...>... >...>; } ; ``` Limitations: - only supported in template arguments and bases, - can only be used inside the templates, even if non-dependent, - the builtins cannot be assigned to template template parameters. The actual implementation proceeds as follows: - When the compiler encounters a `__builtin_dedup_pack` or other type-producing builtin with dependent arguments, it creates a dependent `TemplateSpecializationType`. - During substitution, if the template arguments are non-dependent, we will produce: a new type `SubstBuiltinTemplatePackType`, which stores an argument pack that needs to be substituted. This type is similar to the existing `SubstTemplateParmPack` in that it carries the argument pack that needs to be expanded further. The relevant code is shared. - On top of that, Clang also wraps the resulting type into `TemplateSpecializationType`, but this time only as a sugar. - To actually expand those packs, we collect the produced `SubstBuiltinTemplatePackType` inside `CollectUnexpandedPacks`. Because we know the size of the produces packs only after the initial substitution, places that do the actual expansion will need to have a second run over the substituted type to finalize the expansions (in this patch we only support this for template arguments, see `ExpandTemplateArgument`). If the expansion are requested in the places we do not currently support, we will produce an error. More follow-up work will be needed to fully shape this: - adding the builtin that sorts types, - remove the restrictions for expansions, - implementing P3115R0 (scheduled for C++29, see https://github.com/cplusplus/papers/issues/2300).
2025-08-09[clang] Improve nested name specifier AST representation (#147835)Matheus Izvekov1-12/+17
This is a major change on how we represent nested name qualifications in the AST. * The nested name specifier itself and how it's stored is changed. The prefixes for types are handled within the type hierarchy, which makes canonicalization for them super cheap, no memory allocation required. Also translating a type into nested name specifier form becomes a no-op. An identifier is stored as a DependentNameType. The nested name specifier gains a lightweight handle class, to be used instead of passing around pointers, which is similar to what is implemented for TemplateName. There is still one free bit available, and this handle can be used within a PointerUnion and PointerIntPair, which should keep bit-packing aficionados happy. * The ElaboratedType node is removed, all type nodes in which it could previously apply to can now store the elaborated keyword and name qualifier, tail allocating when present. * TagTypes can now point to the exact declaration found when producing these, as opposed to the previous situation of there only existing one TagType per entity. This increases the amount of type sugar retained, and can have several applications, for example in tracking module ownership, and other tools which care about source file origins, such as IWYU. These TagTypes are lazily allocated, in order to limit the increase in AST size. This patch offers a great performance benefit. It greatly improves compilation time for [stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for `test_on2.cpp` in that project, which is the slowest compiling test, this patch improves `-c` compilation time by about 7.2%, with the `-fsyntax-only` improvement being at ~12%. This has great results on compile-time-tracker as well: ![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831) This patch also further enables other optimziations in the future, and will reduce the performance impact of template specialization resugaring when that lands. It has some other miscelaneous drive-by fixes. About the review: Yes the patch is huge, sorry about that. Part of the reason is that I started by the nested name specifier part, before the ElaboratedType part, but that had a huge performance downside, as ElaboratedType is a big performance hog. I didn't have the steam to go back and change the patch after the fact. There is also a lot of internal API changes, and it made sense to remove ElaboratedType in one go, versus removing it from one type at a time, as that would present much more churn to the users. Also, the nested name specifier having a different API avoids missing changes related to how prefixes work now, which could make existing code compile but not work. How to review: The important changes are all in `clang/include/clang/AST` and `clang/lib/AST`, with also important changes in `clang/lib/Sema/TreeTransform.h`. The rest and bulk of the changes are mostly consequences of the changes in API. PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just for easier to rebasing. I plan to rename it back after this lands. Fixes #136624 Fixes https://github.com/llvm/llvm-project/issues/43179 Fixes https://github.com/llvm/llvm-project/issues/68670 Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-04[Clang] Initial support for P2841 (Variable template and concept template ↵Corentin Jabot1-25/+60
parameters) (#150823) This is a first pass at implementing [P2841R7](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2841r7.pdf). The implementation is far from complete; however, I'm aiming to do that in chunks, to make our lives easier. In particular, this does not implement - Subsumption - Mangling - Satisfaction checking is minimal as we should focus on #141776 first (note that I'm currently very stuck) FTM, release notes, status page, etc, will be updated once the feature is more mature. Given the state of the feature, it is not yet allowed in older language modes. Of note: - Mismatches between template template arguments and template template parameters are a bit wonky. This is addressed by #130603 - We use `UnresolvedLookupExpr` to model template-id. While this is pre-existing, I have been wondering if we want to introduce a different OverloadExpr subclass for that. I did not make the change in this patch.
2025-07-07[C23] Fix typeof handling in enum declarations (#146394)Aaron Ballman1-2/+2
We have a parsing helper function which parses either a parenthesized expression or a parenthesized type name. This is used when parsing a unary operator such as sizeof, for example. The problem this solves is when that construct is ambiguous. Consider: enum E : typeof(int) { F }; After we've parsed the 'typeof', what ParseParenExpression() is responsible for is '(int) { F }' which looks like a compound literal expression when it's actually the parens and operand for 'typeof' followed by the enumerator list for the enumeration declaration. Then consider: sizeof (int){ 0 }; After we've parsed 'sizeof', ParseParenExpression is responsible for parsing something grammatically similar to the problematic case. The solution is to recognize that the expression form of 'typeof' is required to have parentheses. So we know the open and close parens that ParseParenExpression handles must be part of the grammar production for the operator, not part of the operand expression itself. Fixes #146351
2025-06-13Remove delayed typo expressions (#143423)Aaron Ballman1-2/+1
This removes the delayed typo correction functionality from Clang (regular typo correction still remains) due to fragility of the solution. An RFC was posted here: https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631 and while that RFC was asking for folks to consider stepping up to be maintainers, and we did have a few new contributors show some interest, experiments show that it's likely worth it to remove this functionality entirely and focus efforts on improving regular typo correction. This removal fixes ~20 open issues (quite possibly more), improves compile time performance by roughly .3-.4% (https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date), and does not appear to regress diagnostic behavior in a way we wouldn't find acceptable. Fixes #142457 Fixes #139913 Fixes #138850 Fixes #137867 Fixes #137860 Fixes #107840 Fixes #93308 Fixes #69470 Fixes #59391 Fixes #58172 Fixes #46215 Fixes #45915 Fixes #45891 Fixes #44490 Fixes #36703 Fixes #32903 Fixes #23312 Fixes #69874
2025-05-26[Parse] Remove unused includes (NFC) (#141524)Kazu Hirata1-2/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-14[clang][NFC] Regroup declarations in `Parser` (#138511)Vlad Serebrennikov1-233/+0
Following the steps of #82217, this patch reorganizes declarations in `Parse.h`. Highlights are: 1) Declarations are grouped in the same fashion as in `Sema.h`. Table of contents is provided at the beginning of `Parser` class. `public` declaration go first, then `private` ones, but unlike `Sema`, most of the stuff in `Parser` is private. 2) Documentation has been moved from `.cpp` files to the header. Grammar was consistently put in `\verbatim` blocks to render nicely in Doxygen. 3) File has been formatted with clang-format, except for the grammar, because clang-format butchers it.
2025-04-30[clang][NFC] Convert `Parser::TentativeCXXTypeIdContext` to scoped enumVlad Serebrennikov1-1/+1
2025-04-30[clang][NFC] Convert `Parser::TypeCastState` to scoped enumVlad Serebrennikov1-1/+2
2025-04-30[clang][NFC] Convert `ParsedTemplateInfo::Kind` to scoped enumVlad Serebrennikov1-4/+4
2025-03-19[Clang] Increase the default expression nesting limit (#132021)cor3ntin1-0/+7
This iterates on #104717 (which we had to revert) In a bid to increase our chances of success, we try to avoid blowing up the stack by - Using `runWithSufficientStackSpace` in ParseCompoundStatement - Reducing the size of `StmtVector` a bit - Reducing the size of `DeclsInGroup` a bit - Removing a few `ParsedAttributes` from the stacks in places where they are not strictly necessary. `ParsedAttributes` is a _huge_ object On a 64 bits system, the following stack size reductions are observed ``` ParseStatementOrDeclarationAfterAttributes: 344 -> 264 ParseStatementOrDeclaration: 520 -> 376 ParseCompoundStatementBody: 1080 -> 1016 ParseDeclaration: 264 -> 120 ``` Fixes #94728
2024-11-18[Parse] Remove ParseDiagnostic.h (#116496)Kazu Hirata1-1/+1
This patch removes clang/Parse/ParseDiagnostic.h because it just forwards to clang/Basic/DiagnosticParse.h.
2024-10-10[Clang][Parser] Don't evaluate concept when its definition is invalid (#111179)Younan Zhang1-0/+4
Since #103867, the nullness of the concept declaration has been turned to represent a state in which the concept definition is being parsed and used for self-reference checking. However, PR missed a case where such a definition could be invalid, and we shall inhibit making it into evaluation. Fixes https://github.com/llvm/llvm-project/issues/109780
2024-09-04[Clang] Treat default template argument as constant expressions (#107073)cor3ntin1-1/+1
We only check that a default argument is a converted constant expression when using the default argument. However, when parsing a default argument, we need to make sure to parse it as a constant expression such as not ODR-use variables. (otherwise, we would try to capture default template arguments of generic lambdas) Fixes #107048
2024-08-14[Clang] Adjust concept definition locus (#103867)cor3ntin1-3/+11
Per [basic.scope], the locus of a concept is immediately after the introduction of its name. This let us provide better diagnostics for attempt to define recursive concepts. Note that recursive concepts are not supported per https://eel.is/c++draft/basic#scope.pdecl-note-3, but there is no normative wording for that restriction. This is a known defect introduced by [p1787r6](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html). Fixes #55875
2024-07-16[clang] Inject tokens containing #embed back into token stream (#97274)Mariya Podchishchaeva1-29/+12
Instead of playing "whack a mole" with places where #embed should be expanded as comma-separated list, just inject each byte as a token back into the stream, separated by commas.
2024-06-20Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)Mariya Podchishchaeva1-12/+29
This commit implements the entirety of the now-accepted [N3017 -Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. This reverts commit https://github.com/llvm/llvm-project/commit/682d461d5a231cee54d65910e6341769419a67d7. --------- Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
2024-06-12Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C ↵Vitaly Buka1-29/+12
and Obj-C++ by-proxy)" (#95299) Reverts llvm/llvm-project#68620 Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
2024-06-12[clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and ↵The Phantom Derpstorm1-12/+29
Obj-C++ by-proxy) (#68620) This commit implements the entirety of the now-accepted [N3017 - Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com> Co-authored-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
2024-05-17[clang] Introduce `SemaCodeCompletion` (#92311)Vlad Serebrennikov1-2/+2
This patch continues previous efforts to split `Sema` up, this time covering code completion. Context can be found in #84184. Dropping `Code` prefix from function names in `SemaCodeCompletion` would make sense, but I think this PR has enough changes already. As usual, formatting changes are done as a separate commit. Hopefully this helps with the review.
2024-05-17[clang][NFC] Remove `const_cast` from `ParseClassSpecifier`Vlad Serebrennikov1-1/+2
2024-05-17[clang] Implement CWG2428 "Deprecating a concept" (#92295)Vlad Serebrennikov1-6/+11
This patch allows attributes to be attached to C++20 concepts, implementing [CWG2428](https://cplusplus.github.io/CWG/issues/2428.html).
2024-04-23[Clang][Parser] Don't always destroy template annotations at the end of a ↵Younan Zhang1-0/+5
declaration (#89494) Since [6163aa9](https://github.com/llvm/llvm-project/commit/6163aa96799cbad7f2f58e02c5bebee9647056a5#diff-3a7ef0bff7d2b73b4100de636f09ea68b72eda191b39c8091a6a1765d917c1a2), we have introduced an optimization that almost always destroys TemplateIdAnnotations at the end of a function declaration. This doesn't always work properly: a lambda within a default template argument could also result in such deallocation and hence a use-after-free bug while building a type constraint on the template parameter. This patch adds another flag to the parser to tell apart cases when we shouldn't do such cleanups eagerly. A bit complicated as it is, this retains the optimization on a highly templated function with lots of generic lambdas. Note the test doesn't always trigger a conspicuous bug/crash even with a debug build. But a sanitizer build can detect them, I believe. Fixes https://github.com/llvm/llvm-project/issues/67235 Fixes https://github.com/llvm/llvm-project/issues/89127
2024-04-11[Clang][AST] Track whether template template parameters used the 'typename' ↵Krystian Stasiowski1-4/+5
keyword (#88139) This patch adds a `Typename` bit-field to `TemplateTemplateParmDecl` which stores whether the template template parameter was declared with the `typename` keyword.
2024-04-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-2/+2
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-02-01[Clang][Parse] Diagnose member template declarations with multiple ↵Krystian Stasiowski1-166/+40
declarators (#78243) According to [temp.pre] p5: > In a template-declaration, explicit specialization, or explicit instantiation the init-declarator-list in the declaration shall contain at most one declarator. A member-declaration that is a template-declaration or explicit-specialization contains a declaration, even though it declares a member. This means it _will_ contain an init-declarator-list (not a member-declarator-list), so [temp.pre] p5 applies. This diagnoses declarations such as: ``` struct A { template<typename T> static const int x = 0, f(); // error: a template declaration can only declare a single entity template<typename T> static const int g(), y = 0; // error: a template declaration can only declare a single entity }; ``` The diagnostic messages are the same as those of the equivalent namespace scope declarations. Note: since we currently do not diagnose declarations with multiple abbreviated function template declarators at namespace scope e.g., `void f(auto), g(auto);`, so this patch does not add diagnostics for the equivalent member declarations. This patch also refactors `ParseSingleDeclarationAfterTemplate` (now named `ParseDeclarationAfterTemplate`) to call `ParseDeclGroup` and return the resultant `DeclGroup`.
2023-12-01[Clang] Implement P2308R1 - Template Parameter Initialization. (#73103)cor3ntin1-3/+8
https://wiki.edg.com/pub/Wg21kona2023/StrawPolls/p2308r1.html This implements P2308R1 as a DR and resolves CWG2459, CWG2450 and CWG2049. Fixes #73666 Fixes #58434 Fixes #41227 Fixes #49978 Fixes #36296
2023-08-04[Clang] Implement P2169 A nice placeholder with no nameCorentin Jabot1-0/+4
This is a C++ feature that allows the use of `_` to declare multiple variable of that name in the same scope; these variables can then not be referred to. In addition, while P2169 does not extend to parameter declarations, we stop warning on unused parameters of that name, for consistency. The feature is backported to all C++ language modes. Reviewed By: #clang-language-wg, aaron.ballman Differential Revision: https://reviews.llvm.org/D153536
2023-07-17[clang] Fix delayed template parsingSerge Pavlov1-0/+1
Commit 98390ccb80569e8fbb20e6c996b4b8cff87fbec6 fixed late template instantiation by clearing FP pragma stack before instantiation. This solution was based on the assumptions: - FP pragma stack is not used anymore and it is safe to clear it, - Default FP options are determined by command line options. Both the assumptions are wrong. When compilation produces precompiled header file, state of the stack is serialized and then restored when the precompiled header is used. Delayed template parsing occurs at the end of translation unit but before serialization, so clearing FP pragma stack effects serialized representation. When the precompiled file is loaded, some conditions can be broken and clang crashed, it was described in https://github.com/llvm/llvm-project/issues/63704. The crash was observed only in few cases, on most buildbots it was absent. The violation of expected conditions was caused by violation of the second assumption. FPEvalMethod can be modified by target, so it is not possible to deduce it from LangOptions only. So default FP state read from precompiled header was different from the state in the initialized Sema, and this was the crash reason. Only two targets do such modification of default FP options, these are i386 and AIX. so the problem was hard to reproduce. Delayed template parsing should occur with empty pragma stack, so it must be cleared before the instantiation, but the stack now is saved and restored after the instantiation is done. This change should fix https://github.com/llvm/llvm-project/issues/63704. Differential Revision: https://reviews.llvm.org/D155380
2023-07-05[Clang] Reset FP options before function instantiationsSerge Pavlov1-0/+4
This is recommit of 98390ccb80569e8fbb20e6c996b4b8cff87fbec6, reverted in 82a3969d710f5fb7a2ee4c9afadb648653923fef, because it caused https://github.com/llvm/llvm-project/issues/63542. Although the problem described in the issue is independent of the reverted patch, fail of PCH/late-parsed-instantiations.cpp indeed obseved on PowerPC and is likely to be caused by wrong serialization of `LateParsedTemplate` objects. In this patch the serialization is fixed. Original commit message is below. Previously function template instantiations occurred with FP options that were in effect at the end of translation unit. It was a problem for late template parsing as these FP options were used as attributes of AST nodes and may result in crash. To fix it FP options are set to the state of the point of template definition. Differential Revision: https://reviews.llvm.org/D143241
2023-06-29Revert "[Clang] Reset FP options before function instantiations"Serge Pavlov1-4/+0
This reverts commit 98390ccb80569e8fbb20e6c996b4b8cff87fbec6. It caused issue #63542.
2023-06-28[Clang] Reset FP options before function instantiationsSerge Pavlov1-0/+4
Previously function template instantiations occurred with FP options that were in effect at the end of translation unit. It was a problem for late template parsing as these FP options were used as attributes of AST nodes and may result in crash. To fix it FP options are set to the state of the point of template definition. Differential Revision: https://reviews.llvm.org/D143241
2023-06-02[Clang][Parser] Accept GNU attributes preceding C++ attributes on templatesElizabeth Andrews1-1/+12
Clang was rejecting valid code where GNU style attributes preceded C++ style attributes in template declarations as follows: template<int a> __attribute__((deprecated("oh no!"))) [[deprecated("oh no!")]] void foo(); This PR fixes the bug. Differential Revision: https://reviews.llvm.org/D151837
2023-05-26[Clang] Correctly handle generic lambda used as default template argument.Corentin Jabot1-1/+16
Adjust the template pparameter depth when parsing default template arguments as they may introduce generic lambda whose parameters are not substituted at the same depth. Fixes #62611 Reviewed By: erichkeane, #clang-language-wg Differential Revision: https://reviews.llvm.org/D151342
2023-05-15[clang][parser] Fix namespace dropping after malformed declarationsAlejandro Álvarez Ayllón1-4/+1
* After a malformed top-level declaration * After a malformed templated class method declaration In both cases, when there is a malformed declaration, any following namespace is dropped from the AST. This can trigger a cascade of confusing diagnostics that may hide the original error. An example: ``` // Start #include "SomeFile.h" template <class T> void Foo<T>::Bar(void* aRawPtr) { (void)(aRawPtr); } // End #include "SomeFile.h" int main() {} ``` We get the original error, plus 19 others from the standard library. With this patch, we only get the original error. clangd can also benefit from this patch, as namespaces following the malformed declaration is now preserved. i.e. ``` MACRO_FROM_MISSING_INCLUDE("X") namespace my_namespace { //... } ``` Before this patch, my_namespace is not visible for auto-completion. Differential Revision: https://reviews.llvm.org/D150258
2023-05-04[clang][Sema][NFC] Move `EnterExpressionEvaluationContext` to its own fileDavid Stone1-0/+1
Sema.h is huge. This makes a small reduction to it by moving EnterExpressionEvaluationContext into a new header, since it is an independent component. Differential Revision: https://reviews.llvm.org/D149796
2023-04-17[Parse] Remove TimeTraceScope for "ParseTemplate"Fangrui Song1-6/+0
Fix https://github.com/llvm/llvm-project/issues/56554 ``` #include "1.h" #include "2.h" int foo(); ``` Suppose that 1.h ends with a template function. When parsing the function, the `ParseFunctionDefinition` call after the TimeTraceScope object may consume a `r_brace` token and lex the end of file (1.h), resulting in an ExitFile event in SemaPPCallbacks::FileChanged. This event will call `llvm::timeTraceProfilerEnd();`, which incorrectly ends "ParseTemplate" instead of "Source" (1.h). Once 2.h has been fully parsed, the destructor of 1.h's TimeTraceScope object will end "Source" (1.h). This behavior erroneously extends the end of "Source" (1.h), which makes "Source" (2.h) appear to be nested inside "Source" (1.h). This bug is difficult to fix correctly in an elegant way, and we have two options: either end "ParseTemplate" when ending "Source" (1.h), or delay the ExitFile event. However, both approaches require complex code. For now, we can remove the "ParseTemplate" TimeTraceScope. This can be re-added if properly repaired. Reviewed By: anton-afanasyev Differential Revision: https://reviews.llvm.org/D148410
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-28Stop accepting 'bool' in a concept declaration as an extension.Erich Keane1-1/+1
We no longer support the concepts-ts flag for this release, so stop supporting this concepts-ts compat extension as well.
2022-10-27[P0857R0 Part-B] Allows `require' clauses appearing inLiming Liu1-11/+21
template-template parameters. Although it effects whether a template can be used as an argument for another template, the constraint seems not to be checked, nor other major implementations (GCC, MSVC, et al.) check it. Additionally, Part-A of the document seems to have been implemented. So mark P0857R0 as completed. Differential Revision: https://reviews.llvm.org/D134128
2022-09-28[C++2a] P0634r3: Down with typename!Nicolas Lesser1-3/+6
This patch implements P0634r3 that removes the need for 'typename' in certain contexts. For example, ``` template <typename T> using foo = T::type; // ok ``` This is also allowed in previous language versions as an extension, because I think it's pretty useful. :) Reviewed By: #clang-language-wg, erichkeane Differential Revision: https://reviews.llvm.org/D53847
2022-08-26[clang] Add cxx scope if needed for requires clause.Luke Nihlen1-1/+7
Fixes issue #55216. Patch by Luke Nihlen! (luken@google.com, luken-google@) Reviewed By: #clang-language-wg, aaron.ballman Differential Revision: https://reviews.llvm.org/D132503
2022-06-28[Clang] Fix: Restore warning inadvertently removed by D126061.Martin Boehme1-1/+1
Before D126061, Clang would warn about this code ``` struct X { [[deprecated]] struct Y {}; }; ``` with the warning attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration D126061 inadvertently caused this warning to no longer be emitted. This patch restores the previous behavior. The reason for the bug is that after D126061, C++11 attributes applied to a member declaration are no longer placed in `DS.getAttributes()` but are instead tracked in a separate list (`DeclAttrs`). In the case of a free-standing decl-specifier-seq, we would simply ignore the contents of this list. Instead, we now pass the list on to `Sema::ParsedFreeStandingDeclSpec()` so that it can issue the appropriate warning. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D128499
2022-06-15[clang] Reject non-declaration C++11 attributes on declarationsMartin Boehme1-5/+6
For backwards compatiblity, we emit only a warning instead of an error if the attribute is one of the existing type attributes that we have historically allowed to "slide" to the `DeclSpec` just as if it had been specified in GNU syntax. (We will call these "legacy type attributes" below.) The high-level changes that achieve this are: - We introduce a new field `Declarator::DeclarationAttrs` (with appropriate accessors) to store C++11 attributes occurring in the attribute-specifier-seq at the beginning of a simple-declaration (and other similar declarations). Previously, these attributes were placed on the `DeclSpec`, which made it impossible to reconstruct later on whether the attributes had in fact been placed on the decl-specifier-seq or ahead of the declaration. - In the parser, we propgate declaration attributes and decl-specifier-seq attributes separately until we can place them in `Declarator::DeclarationAttrs` or `DeclSpec::Attrs`, respectively. - In `ProcessDeclAttributes()`, in addition to processing declarator attributes, we now also process the attributes from `Declarator::DeclarationAttrs` (except if they are legacy type attributes). - In `ConvertDeclSpecToType()`, in addition to processing `DeclSpec` attributes, we also process any legacy type attributes that occur in `Declarator::DeclarationAttrs` (and emit a warning). - We make `ProcessDeclAttribute` emit an error if it sees any non-declaration attributes in C++11 syntax, except in the following cases: - If it is being called for attributes on a `DeclSpec` or `DeclaratorChunk` - If the attribute is a legacy type attribute (in which case we only emit a warning) The standard justifies treating attributes at the beginning of a simple-declaration and attributes after a declarator-id the same. Here are some relevant parts of the standard: - The attribute-specifier-seq at the beginning of a simple-declaration "appertains to each of the entities declared by the declarators of the init-declarator-list" (https://eel.is/c++draft/dcl.dcl#dcl.pre-3) - "In the declaration for an entity, attributes appertaining to that entity can appear at the start of the declaration and after the declarator-id for that declaration." (https://eel.is/c++draft/dcl.dcl#dcl.pre-note-2) - "The optional attribute-specifier-seq following a declarator-id appertains to the entity that is declared." (https://eel.is/c++draft/dcl.dcl#dcl.meaning.general-1) The standard contains similar wording to that for a simple-declaration in other similar types of declarations, for example: - "The optional attribute-specifier-seq in a parameter-declaration appertains to the parameter." (https://eel.is/c++draft/dcl.fct#3) - "The optional attribute-specifier-seq in an exception-declaration appertains to the parameter of the catch clause" (https://eel.is/c++draft/except.pre#1) The new behavior is tested both on the newly added type attribute `annotate_type`, for which we emit errors, and for the legacy type attribute `address_space` (chosen somewhat randomly from the various legacy type attributes), for which we emit warnings. Depends On D111548 Reviewed By: aaron.ballman, rsmith Differential Revision: https://reviews.llvm.org/D126061
2022-05-13[OpenMP] Fix declare simd use on in-class member template functionMike Rice1-3/+6
Return the Decl when parsing the template member declaration so the 'omp declare simd' pragma can be applied to it. Previously a nullptr was returned causing an error applying the pragma. Fixes #52700. Differential Revision: https://reviews.llvm.org/D125493
2022-04-06[Clang][Sema] Prohibit statement expression in the default argumentJun Zhang1-11/+17
As statement expression makes no sense in the default argument, this patch tries to disable it in the all cases. Please note that the statement expression is a GNU extension, which means that Clang should be consistent with GCC. However, there's no response from GCC devs since we have raised the issue for several weeks. In this case, I think we can disallow statement expressions as a default parameter in general for now, and relax the restriction if GCC folks decide to retain the feature for functions but not lambdas in the future. Related discussion: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104765 Fixes https://github.com/llvm/llvm-project/issues/53488 Differential Revision: https://reviews.llvm.org/D119609
2022-03-24[clang][parse] Move source range into ParsedAttibutesViewTimm Bäder1-1/+1
Move the SourceRange from the old ParsedAttributesWithRange into ParsedAttributesView, so we have source range information available everywhere we use attributes. This also removes ParsedAttributesWithRange (replaced by simply using ParsedAttributes) and ParsedAttributesVieWithRange (replaced by using ParsedAttributesView). Differential Revision: https://reviews.llvm.org/D121201
2022-02-19Fix Wdocumentation unknown parameter warningSimon Pilgrim1-2/+0