summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Removed stale comment. NFC.Serge Pavlov2017-02-151-2/+0
| | | | | | | The case of extern inline functions in GNU89 mode is now handled in `canRedefineFunction`, which has appropriate comment. llvm-svn: 295167
* Revert r294910 and recommit r294861 and r294862 with a target triple to ↵Aaron Ballman2017-02-121-4/+5
| | | | | | hopefully appease the bots. llvm-svn: 294911
* Revert "Attributes on K&R C functions should not cause incompatible..."Renato Golin2017-02-121-5/+4
| | | | | | | | | | | | | | | | ...function type with a redeclaration having the same attribute. Fixing this introduced a secondary problem where we were assuming that K&R functions could not be attributed types when reporting old-style function definitions that are not preceded by a prototype." Also Revert "Hopefully fixes a compile error introduced by r294861." This reverts commit r294862, r294861, as they bork the ARM builds and haven't fix it back. Also, please, short commit titles, long commit decsriptions... llvm-svn: 294910
* Attributes on K&R C functions should not cause incompatible function type ↵Aaron Ballman2017-02-111-4/+5
| | | | | | | | with a redeclaration having the same attribute. Fixing this introduced a secondary problem where we were assuming that K&R functions could not be attributed types when reporting old-style function definitions that are not preceded by a prototype. This patch fixes PR31020. llvm-svn: 294861
* [c++1z] Diagnose attempts to use variables with deduced class templateRichard Smith2017-02-101-4/+4
| | | | | | specialization types from within their own initializers. llvm-svn: 294796
* [c++1z] Require an initializer for deduced class template specialization types.Richard Smith2017-02-101-9/+9
| | | | | | | | It's actually meaningful and useful to allow such variables to have no initializer, but we are strictly following the standard here until the C++ committee reaches consensus on allowing this. llvm-svn: 294785
* [c++1z] In class template argument deduction, all declarators must deduce ↵Richard Smith2017-02-101-6/+7
| | | | | | the same type (just like with auto deduction). llvm-svn: 294700
* [c++1z] P0512R0: support for 'explicit' specifier on deduction-guides.Richard Smith2017-02-101-5/+6
| | | | llvm-svn: 294693
* Disallow explicit instantiation and explicit specialization for deduction ↵Richard Smith2017-02-091-1/+9
| | | | | | guides. llvm-svn: 294641
* Rename IsExplicitSpecialization -> IsMemberSpecialization when we're talkingRichard Smith2017-02-091-31/+31
| | | | | | about member specializations to avoid ambiguous and confusing terminology. llvm-svn: 294622
* [c++1z] P0091R3: Basic support for deducing class template arguments via ↵Richard Smith2017-02-091-46/+57
| | | | | | deduction-guides. llvm-svn: 294613
* P0091R3: Improved syntactic checking of deduction-guides.Richard Smith2017-02-081-4/+9
| | | | llvm-svn: 294395
* P0091R3: Implement basic parsing support for C++17 deduction-guides.Richard Smith2017-02-071-1/+38
| | | | | | | | | | | We model deduction-guides as functions with a new kind of name that identifies the template whose deduction they guide; the bulk of this patch is adding the new name kind. This gives us a clean way to attach an extensible list of guides to a class template in a way that doesn't require any special handling in AST files etc (and we're going to need these functions we come to performing deduction). llvm-svn: 294266
* Drop 'dllimport' when redeclaring inline function template without the ↵Hans Wennborg2017-02-011-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | attribute (PR31695) For non-template dllimport functions, MSVC allows providing an inline definition without spelling out the attribute again. In the example below, f remains a dllimport function. __declspec(dllimport) int f(); inline int f() { return 42; } int useit() { return f(); } However, for a function template, not putting dllimport on the redeclaration causes it to be dropped. In the example below, f is not dllimport. template <typename> __declspec(dllimport) int f(); template <typename> inline int f() { return 42; } int useit() { return f<int>(); } This patch makes Clang match MSVC for the second example. MSVC does not warn about the attribute being dropped in the example above, but I think we should. (MSVC does warn if the inline keyword isn't used.) Differential Revision: https://reviews.llvm.org/D29152 llvm-svn: 293800
* Revert r293585 "Add better ODR checking for modules."Sam McCall2017-01-311-4/+1
| | | | | | | | | | | We're seeing what we believe are false positives. (It's hard to tell with the available diagnostics, and I'm not sure how to reduce them yet). I'll send Richard reproduction details offline. djasper/chandlerc suggested this should be a warning for now, to make rolling it out feasible. llvm-svn: 293611
* Add better ODR checking for modules.Richard Trieu2017-01-311-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When objects are imported for modules, there is a chance that a name collision will cause an ODR violation. Previously, only a small number of such violations were detected. This patch provides a stronger check based on AST nodes. The information needed to uniquely identify an object is taked from the AST and put into a one-dimensional byte stream. This stream is then hashed to give a value to represent the object, which is stored with the other object data in the module. When modules are loaded, and Decl's are merged, the hash values of the two Decl's are compared. Only Decl's with matched hash values will be merged. Mismatch hashes will generate a module error, and if possible, point to the first difference between the two objects. The transform from AST to byte stream is a modified depth first algorithm. Due to references between some AST nodes, a pure depth first algorithm could generate loops. For Stmt nodes, a straight depth first processing occurs. For Type and Decl nodes, they are replaced with an index number and only on first visit will these nodes be processed. As an optimization, boolean values are saved and stored together in reverse order at the end of the byte stream to lower the ammount of data that needs to be hashed. Compile time impact was measured at 1.5-2.0% during module building, and negligible during builds without module building. Differential Revision: https://reviews.llvm.org/D21675 llvm-svn: 293585
* Towards P0091R3: parsing support for class template argument deduction in ↵Richard Smith2017-01-301-10/+6
| | | | | | | | | typename-specifiers. This reinstates r293455, reverted in r293455, with a fix for cv-qualifier handling on dependent typename-specifiers. llvm-svn: 293544
* Revert r293455, which breaks v8 with a spurious error. Testcase added.Sam McCall2017-01-301-6/+10
| | | | | | | | | | | | Summary: Revert r293455, which breaks v8 with a spurious error. Testcase added. Reviewers: klimek Subscribers: cfe-commits, rsmith Differential Revision: https://reviews.llvm.org/D29271 llvm-svn: 293473
* Towards P0091R3: parsing support for class template argument deduction in ↵Richard Smith2017-01-301-10/+6
| | | | | | typename-specifiers. llvm-svn: 293455
* PR31783: Don't request the alignment of an invalid declaration.Richard Smith2017-01-271-1/+2
| | | | | | Fixes an assertion failure on PS4 targets. llvm-svn: 293333
* PR0091R3: Implement parsing support for using templates as types.Richard Smith2017-01-261-28/+56
| | | | | | | | | | | | | | | This change adds a new type node, DeducedTemplateSpecializationType, to represent a type template name that has been used as a type. This is modeled around AutoType, and shares a common base class for representing a deduced placeholder type. We allow deduced class template types in a few more places than the standard does: in conditions and for-range-declarators, and in new-type-ids. This is consistent with GCC and with discussion on the core reflector. This patch does not yet support deduced class template types being named in typename specifiers. llvm-svn: 293207
* PR13403 (+duplicates): implement C++ DR1310 (http://wg21.link/cwg1310).Richard Smith2017-01-191-0/+18
| | | | | | | | | | | | | | | | | | | | | | Under this defect resolution, the injected-class-name of a class or class template cannot be used except in very limited circumstances (when declaring a constructor, in a nested-name-specifier, in a base-specifier, or in an elaborated-type-specifier). This is apparently done to make parsing easier, but it's a pain for us since we don't know whether a template-id using the injected-class-name is valid at the point when we annotate it (we don't yet know whether the template-id will become part of an elaborated-type-specifier). As a tentative resolution to a perceived language defect, mem-initializer-ids are added to the list of exceptions here (they generally follow the same rules as base-specifiers). When the reference to the injected-class-name uses the 'typename' or 'template' keywords, we permit it to be used to name a type or template as an extension; other compilers also accept some cases in this area. There are also a couple of corner cases with dependent template names that we do not yet diagnose, but which will also get this treatment. llvm-svn: 292518
* Give more accurate descriptions of what kind of template we found in ↵Richard Smith2017-01-141-1/+20
| | | | | | | | | diagnostics. We were previouly assuming that every type template was a class template, which is not true any more. llvm-svn: 291988
* Implement DR1265 (wg21.link/cwg1265).Richard Smith2017-01-131-50/+61
| | | | | | | | | | | | Diasllow a declaration using the 'auto' type specifier from using two different meanings of it at once, or from declaring multiple functions with deduced return types or introducing multiple trailing return types. The standard does not technically disallow the multiple trailing return types case if all the declarators declare variables (such as function pointers with trailing return types), but we disallow that too, following the clear intent. llvm-svn: 291880
* Remove redundant passing around of a "ContainsAutoType" flag.Richard Smith2017-01-121-19/+17
| | | | | | | | | | | | This flag serves no purpose other than to prevent us walking through a type to check whether it contains an 'auto' specifier; this duplication of information is error-prone, does not appear to provide any performance benefit, and will become less practical once we support C++1z deduced class template types and eventually constrained types from the Concepts TS. No functionality change intended. llvm-svn: 291737
* This reverts r291628. As suggested by Richard, we can simplyManman Ren2017-01-111-9/+4
| | | | | | | | filter out the implicilty imported modules at CodeGen instead of removing the implicit ImportDecl when an implementation TU of a module imports a header of that same module. llvm-svn: 291688
* Module: Do not create Implicit ImportDecl for module X if weManman Ren2017-01-111-4/+9
| | | | | | | | | are building an implemenation of module X. This fixes a regression caused by r280409. rdar://problem/29930553 llvm-svn: 291628
* [Sema] Avoid -Wshadow warning when a "redefinition of " error is presentedAlex Lorenz2017-01-101-22/+35
| | | | | | | | | | | This commit ensures that clang avoids the redundant -Wshadow warning for variables that already get a "redefinition of " error. rdar://29067894 Differential Revision: https://reviews.llvm.org/D28350 llvm-svn: 291564
* Don't classify variable template names as type templates.Richard Smith2017-01-101-1/+2
| | | | llvm-svn: 291528
* Recommit r289979 [OpenCL] Allow disabling types and declarations associated ↵Yaxun Liu2016-12-181-3/+6
| | | | | | | | with extensions Fixed undefined behavior due to cast integer to bool in initializer list. llvm-svn: 290056
* Revert r289979 due to regressionsYaxun Liu2016-12-161-6/+3
| | | | llvm-svn: 289991
* [OpenCL] Allow disabling types and declarations associated with extensionsYaxun Liu2016-12-161-3/+6
| | | | | | | | | | | | | | | | | | Added a map to associate types and declarations with extensions. Refactored existing diagnostic for disabled types associated with extensions and extended it to declarations for generic situation. Fixed some bugs for types associated with extensions. Allow users to use pragma to declare types and functions for supported extensions, e.g. #pragma OPENCL EXTENSION the_new_extension_name : begin // declare types and functions associated with the extension here #pragma OPENCL EXTENSION the_new_extension_name : end Differential Revision: https://reviews.llvm.org/D21698 llvm-svn: 289979
* [c++1z] Permit constant evaluation of a call through a function pointer whoseRichard Smith2016-12-151-21/+10
| | | | | | | type differs from the type of the actual function due to having a different exception specification. llvm-svn: 289754
* Improve our handling of tag decls in function prototypesReid Kleckner2016-12-141-30/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | r289225 broke AST invariants by reparenting enumerators into function decl contexts. This improves things by only reparenting TagDecls while also attempting to preserve the lexical declcontext chain. The interesting example here is: int f(struct S { enum E { a = 1 } b; } c); The semantic contexts of E and S should be f, and the lexical context of S should be f and the lexical context of E should be S. We didn't do that with r289225, but now we should. This change should also improve our behavior on this example: void f() { extern void ext(struct S { } o); // S injected here } Before r289225 we would only remove 'S' from the surrounding tag injection context if it was the TU, but now we properly reparent S from f to ext. Fixes PR31366 llvm-svn: 289678
* [c++1z] P0217R3: Allow by-value structured binding of arrays.Richard Smith2016-12-141-3/+9
| | | | llvm-svn: 289630
* [OpenCL] Improve address space diagnostics.Egor Churaev2016-12-131-9/+12
| | | | | | | | | | Reviewers: Anastasia Subscribers: bader, yaxunl, cfe-commits Differential Revision: https://reviews.llvm.org/D27671 llvm-svn: 289536
* [c++17] P0490R0, NB comment FI 20: allow direct-initialization of ↵Richard Smith2016-12-091-11/+22
| | | | | | decomposition declarations. llvm-svn: 289286
* Improve error message when referencing a non-tag type with a tagReid Kleckner2016-12-091-5/+17
| | | | | | | | | | | | | | | | | | | | Other compilers accept invalid code here that we reject, and we need a better error message to try to convince users that the code is really incorrect. Consider: class Foo { typedef MyIterHelper<Foo> iterator; friend class iterator; }; Previously our wording was "elaborated type refers to a typedef". "elaborated type" isn't widely known terminology, so the new diagnostic says "typedef 'iterator' cannot be referenced with class specifier". Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D25216 llvm-svn: 289259
* Store decls in prototypes on the declarator instead of in the ASTReid Kleckner2016-12-091-45/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This saves two pointers from FunctionDecl that were being used for some rare and questionable C-only functionality. The DeclsInPrototypeScope ArrayRef was added in r151712 in order to parse this kind of C code: enum e {x, y}; int f(enum {y, x} n) { return x; // should return 1, not 0 } The challenge is that we parse 'int f(enum {y, x} n)' it its own function prototype scope that gets popped before we build the FunctionDecl for 'f'. The original change was doing two questionable things: 1. Saving all tag decls introduced in prototype scope on a TU-global Sema variable. This is problematic when you have cases like this, where 'x' and 'y' shouldn't be visible in 'f': void f(void (*fp)(enum { x, y } e)) { /* no x */ } This patch fixes that, so now 'f' can't see 'x', which is consistent with GCC. 2. Storing the decls in FunctionDecl in ActOnFunctionDeclarator so that they could be used in ActOnStartOfFunctionDef. This is just an inefficient way to move information around. The AST lives forever, but the list of non-parameter decls in prototype scope is short lived. Moving these things to the Declarator solves both of these issues. Reviewers: rsmith Subscribers: jmolloy, cfe-commits Differential Revision: https://reviews.llvm.org/D27279 llvm-svn: 289225
* [CUDA] Ignore implicit target attributes during function template instantiation.Artem Belevich2016-12-081-3/+9
| | | | | | | | | | | | | | | | | | | | | | | Some functions and templates are treated as __host__ __device__ even when they don't have explicitly specified target attributes. What's worse, this treatment may change depending on command line options (-fno-cuda-host-device-constexpr) or #pragma clang force_cuda_host_device. Combined with strict checking for matching function target that comes with D25809(r288962), it makes it hard to write code which would explicitly instantiate or specialize some functions regardless of pragmas or command line options in effect. This patch changes the way we match target attributes of base template vs attributes used in explicit instantiation or specialization so that only explicitly specified attributes are considered. This makes base template selection behave consistently regardless of pragma of command line options that may affect CUDA target. Differential Revision: https://reviews.llvm.org/D25845 llvm-svn: 289091
* [CUDA] Improve target attribute checking for function templates.Artem Belevich2016-12-071-0/+3
| | | | | | | | | | | | * __host__ __device__ functions are no longer considered to be redeclarations of __host__ or __device__ functions. This prevents unintentional merging of target attributes across them. * Function target attributes are not considered (and must match) during explicit instantiation and specialization of function templates. Differential Revision: https://reviews.llvm.org/D25809 llvm-svn: 288962
* Implement the -Wstrict-prototypes warningAlex Lorenz2016-12-071-0/+15
| | | | | | | | | | | | | | | This commit fixes PR20796. It implements the C only -Wstrict-prototypes warning. Clang now emits a warning for function declarations which have no parameters specified and for K&R function definitions with more than 0 parameters that are not preceded by a previous prototype declaration. The patch was originally submitted by Paul Titei! rdar://15060615 Differential Revision: https://reviews.llvm.org/D16533 llvm-svn: 288896
* [modules] Use the "redundant #include" diagnostic rather than the "moduleRichard Smith2016-12-061-7/+1
| | | | | | | | import can't appear here" diagnostic if an already-visible module is textually entered (because we have the module map but not the AST file) within a function/namespace scope. llvm-svn: 288737
* Fix formatting issue from r288207Hans Wennborg2016-11-301-1/+1
| | | | llvm-svn: 288223
* [c++1z] Improve support for -fno-exceptions: we can't just ignore exceptionRichard Smith2016-11-301-9/+0
| | | | | | | | | specifications in this mode in C++17, since they're part of the function type, so check and diagnose them like we would if exceptions were enabled. Better ideas welcome. llvm-svn: 288220
* [c++1z] PR31210: ignore exception specification when matching the type of aRichard Smith2016-11-291-3/+19
| | | | | | builtin with the type of an explicit declaration of the same function. llvm-svn: 288208
* Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)Hans Wennborg2016-11-291-0/+3
| | | | llvm-svn: 288207
* [OpenCL] Prohibit using reserve_id_t in program scope.Alexey Bader2016-11-291-50/+55
| | | | | | | | | | | | Patch by Egor Churaev (echuraev). Reviewers: Anastasia Subscribers: cfe-commits, yaxunl, bader Differential Revision: https://reviews.llvm.org/D27099 llvm-svn: 288126
* Use descriptive message if list initializer is incorrectly parenthesized.Serge Pavlov2016-11-121-0/+24
| | | | | | | | | | | | | If initializer contains parentheses around braced list where it is not allowed, as in construct int({0}), clang issued message like `functional-style cast from 'void' to 'int' is not allowed`, which does not help much. Both gcc and msvc issue message `list-initializer for non-class type must not be parenthesized`, which is more descriptive. This change implements similar message for clang. Differential Revision: https://reviews.llvm.org/D25816 llvm-svn: 286721
* Remove double setting of invalid flag.Richard Trieu2016-11-111-2/+0
| | | | | | | | In r286630, Decl::setInvalidDecl will automatically set the invalid flag for BindingDecl for children in invalid DecompositionDecl. It no longer is necessary to do a separate setInvalidDecl when finalizing a BindingDecl. llvm-svn: 286641
OpenPOWER on IntegriCloud