summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX
Commit message (Collapse)AuthorAgeFilesLines
* Follow-up to r281367: Compare uuids case-insensitively.Nico Weber2016-09-141-1/+2
| | | | llvm-svn: 281430
* [clang-cl] Diagnose duplicate uuids.Nico Weber2016-09-131-0/+94
| | | | | | | | | | | | This mostly behaves cl.exe's behavior, even though clang-cl is stricter in some corner cases and more lenient in others (see the included test). To make the uuid declared previously here diagnostic work correctly, tweak stripTypeAttributesOffDeclSpec() to keep attributes in the right order. https://reviews.llvm.org/D24469 llvm-svn: 281367
* Add missing test coverage for an inheritance model attrib merge diag.Nico Weber2016-09-101-0/+8
| | | | | | | Without this, no tests fail if I remove the Diag() in the first if in Sema::mergeMSInheritanceAttr(). llvm-svn: 281136
* C++ Modules TS: Add parsing and some semantic analysis support forRichard Smith2016-09-081-0/+68
| | | | | | | export-declarations. These don't yet have an effect on name visibility; we still export everything by default. llvm-svn: 280999
* [Sema] Compare bad conversions in overload resolution.George Burgess IV2016-09-071-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r280553 introduced an issue where we'd emit ambiguity errors for code like: ``` void foo(int *, int); void foo(unsigned int *, unsigned int); void callFoo() { unsigned int i; foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int, // but unsigned int*->unsigned int* is better than // int*->int*. } ``` This patch fixes this issue by changing how we handle ill-formed (but valid) implicit conversions. Candidates with said conversions now always rank worse than candidates without them, and two candidates are considered to be equally bad if they both have these conversions for the same argument. Additionally, this fixes a case in C++11 where we'd complain about an ambiguity in a case like: ``` void f(char *, int); void f(const char *, unsigned); void g() { f("abc", 0); } ``` ...Since conversion to char* from a string literal is considered ill-formed in C++11 (and deprecated in C++03), but we accept it as an extension. llvm-svn: 280847
* Fix clang's handling of the copy performed in the second phase of classRichard Smith2016-09-076-7/+47
| | | | | | | | | | | | | | | | | | | | | | | copy-initialization. We previously got this wrong in a couple of ways: - we only looked for copy / move constructors and constructor templates for this copy, and thus would fail to copy in cases where doing so should use some other constructor (but see core issue 670), - we mishandled the special case for disabling user-defined conversions that blocks infinite recursion through repeated application of a copy constructor (applying it in slightly too many cases) -- though as far as I can tell, this does not ever actually affect the result of overload resolution, and - we misapplied the special-case rules for constructors taking a parameter whose type is a (reference to) the same class type by incorrectly assuming that only happens for copy/move constructors (it also happens for constructors instantiated from templates and those inherited from base classes). These changes should only affect strange corner cases (for instance, where the copy constructor exists but has a non-const-qualified parameter type), so for the most part it only causes us to produce more 'candidate' notes, but see the test changes for other cases whose behavior is affected. llvm-svn: 280776
* Implement __attribute__((require_constant_initialization)) for safe static ↵Eric Fiselier2016-09-021-0/+282
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialization. Summary: This attribute specifies expectations about the initialization of static and thread local variables. Specifically that the variable has a [constant initializer](http://en.cppreference.com/w/cpp/language/constant_initialization) according to the rules of [basic.start.static]. Failure to meet this expectation will result in an error. Static objects with constant initializers avoid hard-to-find bugs caused by the indeterminate order of dynamic initialization. They can also be safely used by other static constructors across translation units. This attribute acts as a compile time assertion that the requirements for constant initialization have been met. Since these requirements change between dialects and have subtle pitfalls it's important to fail fast instead of silently falling back on dynamic initialization. ```c++ // -std=c++14 #define SAFE_STATIC __attribute__((require_constant_initialization)) static struct T { constexpr T(int) {} ~T(); }; SAFE_STATIC T x = {42}; // OK. SAFE_STATIC T y = 42; // error: variable does not have a constant initializer // copy initialization is not a constant expression on a non-literal type. ``` This attribute can only be applied to objects with static or thread-local storage duration. Reviewers: majnemer, rsmith, aaron.ballman Subscribers: jroelofs, cfe-commits Differential Revision: https://reviews.llvm.org/D23385 llvm-svn: 280525
* Revert r280516 since it contained accidental changes.Eric Fiselier2016-09-021-282/+0
| | | | llvm-svn: 280521
* Implement __attribute__((require_constant_initialization)) for safe static ↵Eric Fiselier2016-09-021-0/+282
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialization. Summary: This attribute specifies expectations about the initialization of static and thread local variables. Specifically that the variable has a [constant initializer](http://en.cppreference.com/w/cpp/language/constant_initialization) according to the rules of [basic.start.static]. Failure to meet this expectation will result in an error. Static objects with constant initializers avoid hard-to-find bugs caused by the indeterminate order of dynamic initialization. They can also be safely used by other static constructors across translation units. This attribute acts as a compile time assertion that the requirements for constant initialization have been met. Since these requirements change between dialects and have subtle pitfalls it's important to fail fast instead of silently falling back on dynamic initialization. ```c++ // -std=c++14 #define SAFE_STATIC __attribute__((require_constant_initialization)) static struct T { constexpr T(int) {} ~T(); }; SAFE_STATIC T x = {42}; // OK. SAFE_STATIC T y = 42; // error: variable does not have a constant initializer // copy initialization is not a constant expression on a non-literal type. ``` This attribute can only be applied to objects with static or thread-local storage duration. Reviewers: majnemer, rsmith, aaron.ballman Subscribers: jroelofs, cfe-commits Differential Revision: https://reviews.llvm.org/D23385 llvm-svn: 280516
* DR259: Demote the pedantic error for an explicit instantiation after anRichard Smith2016-08-314-13/+9
| | | | | | | | | explicit specialization to a warning for C++98 mode (this is a defect report resolution, so per our informal policy it should apply in C++98), and turn the warning on by default for C++11 and later. In all cases where it fires, the right thing to do is to remove the pointless explicit instantiation. llvm-svn: 280308
* fix typo "varaible"Nico Weber2016-08-241-1/+1
| | | | llvm-svn: 279639
* PR28423: Compare primary declaration contexts.Vassil Vassilev2016-08-201-0/+5
| | | | | | | | | | | In certain cases (mostly coming from modules), Sema's idea of the StdNamespace does not point to the first declaration of namespace std. Patch by Cristina Cristescu! Reviewed by Richard Smith. llvm-svn: 279371
* Add missing testsRoger Ferrer Ibanez2016-08-172-0/+142
| | | | | | | | Change r278483 was missing the tests Differential Revision: https://reviews.llvm.org/D20561 llvm-svn: 278908
* Disable lambda-capture of decomposition declaration bindings for now, until CWGRichard Smith2016-08-151-0/+10
| | | | | | agrees on how they're supposed to work. llvm-svn: 278648
* P0217R3: code generation support for decomposition declarations.Richard Smith2016-08-151-1/+0
| | | | llvm-svn: 278642
* [Sema] Fix a crash on variadic enable_if functions.George Burgess IV2016-08-121-0/+23
| | | | | | | | | | | | | Currently, when trying to evaluate an enable_if condition, we try to evaluate all arguments a user passes to a function. Given that we can't use variadic arguments from said condition anyway, not converting them is a reasonable thing to do. So, this patch makes us ignore any varargs when attempting to check an enable_if condition. We'd crash because, in order to convert an argument, we need its ParmVarDecl. Variadic arguments don't have ParmVarDecls. llvm-svn: 278471
* P0217R3: serialization/deserialization support for c++17 decomposition ↵Richard Smith2016-08-121-1/+0
| | | | | | declarations. llvm-svn: 278460
* P0217R3: template instantiation support for decomposition declarations.Richard Smith2016-08-121-1/+0
| | | | llvm-svn: 278458
* P0217R3: Constant expression evaluation for decomposition declarations.Richard Smith2016-08-121-3/+19
| | | | llvm-svn: 278447
* P0217R3: Perform semantic checks and initialization for the bindings in aRichard Smith2016-08-111-1/+17
| | | | | | | decomposition declaration for arrays, aggregate-like structs, tuple-like types, and (as an extension) for complex and vector types. llvm-svn: 278435
* Reapply [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-101-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | Reapply r277787. For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 278264
* Fix typos from r277797 and unused variable from r277889.Richard Trieu2016-08-061-3/+0
| | | | llvm-svn: 277900
* Fix two false positives in -Wreturn-stack-addressRichard Trieu2016-08-051-1/+63
| | | | | | | | | | | If the return type is a pointer and the function returns the reference to a pointer, don't warn since only the value is returned, not the reference. If a reference function parameter appears in the reference chain, don't warn since binding happens at the caller scope, so addresses returned are not to local stack. This includes default arguments as well. llvm-svn: 277889
* Fix false positive in -Wunsequenced and templates.Richard Trieu2016-08-051-0/+55
| | | | | | | | | | | | | | For builtin logical operators, there is a well-defined ordering of argument evaluation. For overloaded operator of the same type, there is no argument evaluation order, similar to other function calls. When both are present, uninstantiated templates with an operator&& is treated as an unresolved function call. Unresolved function calls are treated as normal function calls, and may result in false positives when the builtin logical operator is used. Have the unsequenced checker ignore dependent expressions to avoid this false positive. The check also happens in template instantiations to catch when the overloaded operator is used. llvm-svn: 277866
* Revert "[Sema] Add sizeof diagnostics for bzero"Bruno Cardoso Lopes2016-08-051-43/+0
| | | | | | This reverts commit r277787, which caused PR28870. llvm-svn: 277830
* [Sema] Add sizeof diagnostics for bzeroBruno Cardoso Lopes2016-08-041-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | For memset (and others) we can get diagnostics like: struct stat { int x; }; void foo(struct stat *stamps) { bzero(stamps, sizeof(stamps)); memset(stamps, 0, sizeof(stamps)); } t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess] memset(stamps, 0, sizeof(stamps)); ~~~~~~ ^~~~~~ t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)? memset(stamps, 0, sizeof(stamps)); ^~~~~~ This patch implements the same class of warnings for bzero. Differential Revision: https://reviews.llvm.org/D22525 rdar://problem/18963514 llvm-svn: 277787
* [CFG] Fix crash finding destructor of lifetime-extended temporary.Devin Coughlin2016-08-021-0/+15
| | | | | | | | | | | Fix a crash under -Wthread-safety when finding the destructor for a lifetime-extending reference. A patch by Nandor Licker! Differential Revision: https://reviews.llvm.org/D22419 llvm-svn: 277522
* [NFC] Rearrange an example-file so the c++14 specific example is on top.Faisal Vali2016-07-311-10/+12
| | | | | | This makes it easier to add C++1z examples to the bottom, just before the #endif. llvm-svn: 277287
* [Sema] Teach getCurrentThisType to reconize lambda in in-class initializerErik Pilkington2016-07-271-2/+28
| | | | | | | | Fixes PR27994, a crash on valid. Differential revision: https://reviews.llvm.org/D21145 llvm-svn: 276900
* [cxx1z-constexpr-lambda] Make a lambda's closure type eligible as a ↵Faisal Vali2016-07-231-3/+15
| | | | | | | | | | | | | literal-type in C++1z Additionally, for pre-C++1z, instead of forbidding a lambda's closure type from being a literal type through circumlocutorily setting HasNonLiteralTypeFieldsOrBases falsely to true -- handle lambda's more directly in CXXRecordDecl::isLiteral(). One additional small step towards implementing constexpr-lambdas. Thanks to Richard Smith for his review! https://reviews.llvm.org/D22662 llvm-svn: 276514
* P0217R3: Parsing support and framework for AST representation of C++1zRichard Smith2016-07-221-0/+11
| | | | | | | | | | | decomposition declarations. There are a couple of things in the wording that seem strange here: decomposition declarations are permitted at namespace scope (which we partially support here) and they are permitted as the declaration in a template (which we reject). llvm-svn: 276492
* [Sema] Fix PR28623.George Burgess IV2016-07-211-0/+9
| | | | | | | | | | | | | | | In atomic builtins, we assumed that the LValue conversion on the first argument would succeed. So, we would crash given code like: ``` void ovl(char); void ovl(int); __atomic_store_n(ovl, 0, 0); ``` This patch makes us not assume that said conversion is successful. :) llvm-svn: 276232
* [Sema] Compute the nullability of a conditional expression based on theAkira Hatanaka2016-07-201-0/+20
| | | | | | | | | | | | | | nullabilities of its operands. This patch defines a function to compute the nullability of conditional expressions, which enables Sema to precisely detect implicit conversions of nullable conditional expressions to nonnull pointers. rdar://problem/25166556 Differential Revision: https://reviews.llvm.org/D22392 llvm-svn: 276076
* Deprecated (legacy) string literal conversion to 'char *' causes strange ↵Dmitry Polukhin2016-07-191-0/+11
| | | | | | | | | | | | | | overloading resolution It's a patch for PR28050. Seems like overloading resolution wipes out the first standard conversion sequence (before user-defined conversion) in case of deprecated string literal conversion. Differential revision: https://reviews.llvm.org/D21228 Patch by Alexander Makarov llvm-svn: 275970
* Push alias-declarations and alias-template declarations into scope even ifRichard Smith2016-07-151-2/+2
| | | | | | | | they're redeclarations. This is necessary in order for name lookup to correctly find the most recent declaration of the name (which affects default template argument lookup and cross-module merging, among other things). llvm-svn: 275612
* Sema: support __declspec(dll*) on ObjC interfacesSaleem Abdulrasool2016-07-152-12/+24
| | | | | | | | | | | Extend the __declspec(dll*) attribute to cover ObjC interfaces. This was requested by Microsoft for their ObjC support. Cover both import and export. This only adds the semantic analysis portion of the support, code-generation still remains outstanding. Add some basic initial documentation on the attributes that were previously empty. Tweak the previous tests to use the relative expected-warnings to make the tests easier to read. llvm-svn: 275610
* C does not have inline variables.Paul Robinson2016-07-141-0/+13
| | | | | | | | Add a few missing tests for related C++ diagnostics. Differential Revision: http://reviews.llvm.org/D22113 llvm-svn: 275493
* Reverting 275417Roger Ferrer Ibanez2016-07-142-146/+0
| | | | | | This change has triggered unexpected failures. llvm-svn: 275462
* Diagnose taking address and reference binding of packed membersRoger Ferrer Ibanez2016-07-142-0/+146
| | | | | | | | | | | | | | | | | | | | | | | This patch implements PR#22821. Taking the address of a packed member is dangerous since the reduced alignment of the pointee is lost. This can lead to memory alignment faults in some architectures if the pointer value is dereferenced. This change adds a new warning to clang emitted when taking the address of a packed member. A packed member is either a field/data member declared as attribute((packed)) or belonging to a struct/class declared as such. The associated flag is -Waddress-of-packed-member. Conversions (either implicit or via a valid casting) to pointer types with lower or equal alignment requirements (e.g. void* or char*) silence the warning. This change also adds a new error diagnostic when the user attempts to bind a reference to a packed member, regardless of the alignment. Differential Revision: https://reviews.llvm.org/D20561 llvm-svn: 275417
* P0305R0: Semantic analysis and code generation for C++17 init-statement for ↵Richard Smith2016-07-142-0/+117
| | | | | | | | | | 'if' and 'switch': if (stmt; condition) { ... } Patch by Anton Bikineev! Some minor formatting and comment tweets by me. llvm-svn: 275350
* [Sema] Don't artificially forbid BuiltinTemplateDecls in CheckTemplateArgumentDavid Majnemer2016-07-111-1/+1
| | | | | | | | After thinking about it, we don't really need to forbid BuiltinTemplateDecls explicitly. The restriction doesn't really buy us anything. llvm-svn: 275078
* [Sema] Disallow __make_integer_seq from showing up in __make_integer_seqDavid Majnemer2016-07-111-0/+4
| | | | | | | | | We hit over stringent asserts when trying to diagnose. Loosen them as appropriate. This fixes PR28494. llvm-svn: 275047
* Teach -ast-print to print constexpr variables.Vassil Vassilev2016-07-081-1/+3
| | | | | | Patch reviewed by Richard Smith (D22168). llvm-svn: 274930
* Don't crash when printing auto variables.Vassil Vassilev2016-07-081-0/+9
| | | | | | Patch by Axel Naumann! llvm-svn: 274859
* C++14 init-capture: error out instead of crashing.Manman Ren2016-07-011-0/+10
| | | | | | | | | | | | | | | | | | | When we have template arguments, we have a function and a pattern, the variable in init-capture belongs to the pattern decl when checking if the lhs of "max = current" is modifiable: auto find = [max = init](auto current) { max = current; }; In function isReferenceToNonConstCapture, we handle the case where the decl context for the variable is not part of the current context. Instead of crashing, we emit an error message: cannot assign to a variable captured by copy in a non-mutable lambda rdar://26997922 llvm-svn: 274392
* [Feature] Add a builtin for indexing into parameter packs. Patch by Louis ↵Eric Fiselier2016-07-011-0/+45
| | | | | | | | | | | | | Dionne. This patch adds a __nth_element builtin that allows fetching the n-th type of a parameter pack with very little compile-time overhead. The patch was inspired by r252036 and r252115 by David Majnemer, which add a similar __make_integer_seq builtin for efficiently creating a std::integer_sequence. Reviewed as D15421. http://reviews.llvm.org/D15421 llvm-svn: 274316
* [Sema] Implement C++14's DR1579: Prefer returning by converting move constructorErik Pilkington2016-06-301-8/+2
| | | | | | | | Fixes PR28096. Differential Revision: http://reviews.llvm.org/D21619 llvm-svn: 274291
* Fix typo-correction crash if a typo occurs within the operand of aRichard Smith2016-06-302-1/+3
| | | | | | | | | function-style cast to a non-dependent type which is then used in an invalid way. We'd lose the "type dependent" bit here, and downstream Sema processing would then discard the expression if it was used in a context where its type rendered it invalid. llvm-svn: 274267
* PR28373: fix crash-on-invalid if the condition of an if-statement fails ↵Richard Smith2016-06-301-0/+4
| | | | | | typo-correction. llvm-svn: 274260
* [GCC] PR23529 Mangler part of attrbute abi_tag supportDmitry Polukhin2016-06-301-10/+0
| | | | | | | | | | | | | | | | | Original patch by Stefan Bühler http://reviews.llvm.org/D12834 Difference between original and this one: - fixed all failing tests - fixed mangling for global variable outside namespace - emit ABI tags for guards and local names - clang-format + other stylistic changes - significantly reworked patch according to Richard's suggestions Sema part, committed before http://reviews.llvm.org/D17567 Differential revision: http://reviews.llvm.org/D18035 llvm-svn: 274222
OpenPOWER on IntegriCloud