summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/constant-expression-cxx11.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* PR17381: Treat undefined behavior during expression evaluation as an unmodeledRichard Smith2015-12-031-4/+3
| | | | | | | | | | | | | | | | | | | | | side-effect, so that we don't allow speculative evaluation of such expressions during code generation. This caused a diagnostic quality regression, so fix constant expression diagnostics to prefer either the first "can't be constant folded" diagnostic or the first "not a constant expression" diagnostic depending on the kind of evaluation we're doing. This was always the intent, but didn't quite work correctly before. This results in certain initializers that used to be constant initializers to no longer be; in particular, things like: float f = 1e100; are no longer accepted in C. This seems appropriate, as such constructs would lead to code being executed if sanitizers are enabled. llvm-svn: 254574
* Remove warning on over-wide bit-field of boolean type; there's no risk thatRichard Smith2015-09-231-1/+1
| | | | | | | | | | someone thought all the bits would be value bits in this case. Also fix the wording of the warning -- it claimed that the width of 'bool' is 8, which is not correct; the width is 1 bit, whereas the size is 8 bits in our implementation. llvm-svn: 248435
* C11 _Bool bitfield diagnosticRachel Craik2015-09-141-3/+3
| | | | | | | | | | | | Summary: Implement DR262 (for C). This patch will mainly affect bitfields of type _Bool Reviewers: fraggamuffin, rsmith Subscribers: hubert.reinterpretcast, cfe-commits Differential Revision: http://reviews.llvm.org/D10018 llvm-svn: 247618
* PR24597: Fix in-place evaluation of call expressions to provide a proper "this"Richard Smith2015-08-281-0/+12
| | | | | | pointer to an RVO construction of a returned object. llvm-svn: 246263
* Move fixit for const init from note to diag, weaken to warning in MS mode.Nico Weber2015-04-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r235046 turned "extern __declspec(selectany) int a;" from a declaration into a definition to fix PR23242 (required for compatibility with mc.exe output). However, this broke parsing Windows headers: A d3d11 headers contain something like struct SomeStruct {}; extern const __declspec(selectany) SomeStruct some_struct; This is now a definition, and const objects either need an explicit default ctor or an initializer so this errors out with d3d11.h(1065,48) : error: default initialization of an object of const type 'const CD3D11_DEFAULT' without a user-provided default constructor (cl.exe just doesn't implement this rule, independent of selectany.) To work around this, weaken this error into a warning for selectany decls in microsoft mode, and recover with zero-initialization. Doing this is a bit hairy since it adds a fixit on an error emitted by InitializationSequence – this means it needs to build a correct AST, which in turn means InitializationSequence::Failed() cannot return true when this fixit is applied. As a workaround, the patch adds a fixit member to InitializationSequence, and InitializationSequence::Perform() prints the diagnostic if the fixit member is set right after its call to Diagnose. That function is usually called when InitializationSequences are used – InitListChecker::PerformEmptyInit() doesn't call it, but the InitListChecker case never performs default-initialization, so this is technically OK. This is the alternative, original fix for PR20208 that got reviewed in the thread "[patch] Improve diagnostic on default-initializing const variables (PR20208)". This change basically reverts r213725, adds the original fix for PR20208, and makes the error a warning in Microsoft mode. llvm-svn: 235166
* PR17938: This has already been fixed, add regression test.Richard Smith2015-02-131-0/+10
| | | | llvm-svn: 229146
* Sema: Don't crash when variable is redefined as a constexpr functionDavid Majnemer2015-01-091-0/+5
| | | | | | | | | We have a diagnostic describing that constexpr changed in C++14 when compiling in C++11 mode. While doing this, it examines the previous declaration and assumes that it is a function. However it is possible, in the context of error recovery, for this to not be the case. llvm-svn: 225518
* Adding a -Wunused-value warning for expressions with side effects used in an ↵Aaron Ballman2014-12-171-1/+2
| | | | | | unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case. llvm-svn: 224465
* Support constant evaluation for member calls on std::initializer_listRichard Smith2014-12-171-0/+3
| | | | | | temporaries. llvm-svn: 224449
* AST: Limit zero-sized constexpr behavior to array typesDavid Majnemer2014-12-141-1/+2
| | | | | | | Restricting this "extension" to array types maximizes our standards conformance while not miscompiling real-world programs. llvm-svn: 224215
* Sema: Constexpr functions must have return statements which have an exprDavid Majnemer2014-12-131-0/+5
| | | | | | | | | | | | | | | clang lets programmers be pretty cavalier when it comes to void return statements in functions which have non-void return types. However, we cannot be so forgiving in constexpr functions: evaluation will go off the rails very quickly. Instead, keep the return statement in the AST but mark the function as invalid. Doing so gives us nice diagnostics while making constexpr evaluation halt. This fixes PR21859. llvm-svn: 224189
* AST: Incomplete types might be zero sizedDavid Majnemer2014-12-111-0/+8
| | | | | | | | Comparing the address of an object with an incomplete type might return true with a 'distinct' object if the former has a size of zero. However, such an object should compare unequal with null. llvm-svn: 224040
* AST: Don't assume two zero sized objects live at different addressesDavid Majnemer2014-12-091-0/+6
| | | | | | | | Zero sized objects may overlap with each other or any other object. This fixes PR21786. llvm-svn: 223852
* Fix bug where a trivial constexpr copy/move operation couldn't copy from anRichard Smith2014-11-191-0/+13
| | | | | | | empty non-constexpr object. Such a copy doesn't break any of the constexpr rules. llvm-svn: 222387
* Handle use of default member initializers before end of outermost classReid Kleckner2014-11-171-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, when we have this situation: struct A { template <typename T> struct B { int m1 = sizeof(A); }; B<int> m2; }; We can't parse m1's initializer eagerly because we need A to be complete. Therefore we wait until the end of A's class scope to parse it. However, we can trigger instantiation of B before the end of A, which will attempt to instantiate the field decls eagerly, and it would build a bad field decl instantiation that said it had an initializer but actually lacked one. Fixed by deferring instantiation of default member initializers until they are needed during constructor analysis. This addresses a long standing FIXME in the code. Fixes PR19195. Reviewed By: rsmith Differential Revision: http://reviews.llvm.org/D5690 llvm-svn: 222192
* Fix assert/crash on invalid with __builtin_constant_p conditionals in ↵Richard Smith2014-11-131-0/+2
| | | | | | constant expressions. llvm-svn: 221942
* PR21327 / C++ DR1652 / C++ DR73: comparing a past-the-end pointer for oneRichard Smith2014-10-211-0/+4
| | | | | | | | complete object to a pointer to the start of another complete object does not evaluate to the constant 'false'. All other comparisons between the addresses of subobjects of distinct complete objects still do. llvm-svn: 220343
* Improve -Wuninitialized to take into account field ordering with initializerRichard Trieu2014-09-231-1/+1
| | | | | | | lists. Since the fields are inititalized one at a time, using a field with lower index to initialize a higher indexed field should not be warned on. llvm-svn: 218339
* Reject a slightly-sneaky way to perform a read of mutable state from within aRichard Smith2014-09-161-0/+43
| | | | | | | | | constexpr function. Part of this fix is a tentative fix for an as-yet-unfiled core issue (we're missing a prohibition against reading mutable members from unions via a trivial constructor/assignment, since that doesn't perform an lvalue-to-rvalue conversion on the members). llvm-svn: 217852
* C++1y is now C++14!Aaron Ballman2014-08-191-12/+12
| | | | | | Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording. llvm-svn: 215982
* Improve diagnostic on default-initializing const variables (PR20208).Nico Weber2014-07-231-1/+1
| | | | | | | | This tweaks the diagnostic wording slighly, and adds a fixit on a note. An alternative would be to add the fixit directly on the diagnostic, see the review thread linked to from the bug for a few notes on that approach. llvm-svn: 213725
* Add an explicit diagnostic for the case where an expression is not a constantRichard Smith2014-07-071-0/+13
| | | | | | expression because it uses 'this'. Inspired by PR20219 comment#2. llvm-svn: 212433
* Add missing "non-constant" diagnostic for a member call on a temporary ofRichard Smith2014-06-111-0/+6
| | | | | | non-literal class type. llvm-svn: 210696
* PR19010: Make sure we initialize (empty) indirect base class subobjects whenRichard Smith2014-03-051-0/+10
| | | | | | evaluating trivial default initialization of a literal class type. llvm-svn: 203025
* PR16074, implement warnings to catch pointer to boolean true and pointer toRichard Trieu2014-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | null comparison when the pointer is known to be non-null. This catches the array to pointer decay, function to pointer decay and address of variables. This does not catch address of function since this has been previously used to silence a warning. Pointer to bool conversion is under -Wbool-conversion. Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group of -Wtautological-compare. void foo() { int arr[5]; int x; // warn on these conditionals if (foo); if (arr); if (&x); if (foo == null); if (arr == null); if (&x == null); if (&foo); // no warning } llvm-svn: 202216
* Modern gcc is happy to constant evaluate __builtin_strlen in various casesRichard Smith2013-11-151-0/+39
| | | | | | | where we didn't. Extend our constant evaluation for __builtin_strlen to handle any constant array of chars, not just string literals, to match. llvm-svn: 194762
* PR17800: When performing pack expansion, we must always rebuild the AST nodesRichard Smith2013-11-071-0/+13
| | | | | | | to avoid breaking AST invariants by reusing Stmt nodes within the same function. llvm-svn: 194217
* Refactor constant expression handling and make a couple of tweaks to make it aRichard Smith2013-11-051-0/+17
| | | | | | | | | bit more robust against future changes. This includes a slight diagnostic improvement: if we know we're only trying to form a constant expression, take the first diagnostic which shows the expression is not a constant expression, rather than preferring the first one which makes the expression unfoldable. llvm-svn: 194098
* Part three of PR15721: if we have an invalid CXXDefaultInitExpr, don't crash ifRichard Smith2013-09-131-0/+18
| | | | | | we try to constant-evaluate it. Patch by Karthik Bhat, test by me. llvm-svn: 190722
* PR5683: Issue a warning when subtracting pointers to types of zero size, andRichard Smith2013-09-101-1/+13
| | | | | | | treat such subtractions as being non-constant. Patch by Serge Pavlov! With a few tweaks by me. llvm-svn: 190439
* PR16755: When initializing or modifying a bitfield member in a constantRichard Smith2013-08-061-0/+37
| | | | | | expression, truncate the stored value to the size of the bitfield. llvm-svn: 187782
* C++1y: track object lifetime during constexpr evaluation, and don't allowRichard Smith2013-07-241-0/+18
| | | | | | | objects to be used once their lifetimes end. This completes the C++1y constexpr extensions. llvm-svn: 187025
* Fix error recovery with in-class initializer.Eli Friedman2013-06-281-0/+15
| | | | | | | | Previously, for a field with an invalid in-class initializer, we would create a CXXDefaultInitExpr referring to a null Expr*. This is not a good idea. llvm-svn: 185216
* More of N3652: don't add an implicit 'const' to 'constexpr' member functions ↵Richard Smith2013-06-251-0/+24
| | | | | | when checking for overloads in C++1y. llvm-svn: 184865
* PR16377: Allow evaluation of statement expressions in constant evaluation,Richard Smith2013-06-201-0/+21
| | | | | | why not. Apparently GCC supports this. llvm-svn: 184396
* Fix handling of const_cast from prvalue to rvalue reference: such a cast isRichard Smith2013-06-141-0/+5
| | | | | | | only permitted if the source object is of class type, and should materialize a temporary for the reference to bind to. llvm-svn: 184017
* Implement core issue 903: only integer literals with value 0 and prvalues ofRichard Smith2013-06-131-6/+13
| | | | | | type std::nullptr_t are null pointer constants from C++11 onwards. llvm-svn: 183883
* PR12086, PR15117Richard Smith2013-06-121-0/+41
| | | | | | | | | | | | | | | | | | | Introduce CXXStdInitializerListExpr node, representing the implicit construction of a std::initializer_list<T> object from its underlying array. The AST representation of such an expression goes from an InitListExpr with a flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr). This more detailed representation has several advantages, the most important of which is that the new MaterializeTemporaryExpr allows us to directly model lifetime extension of the underlying temporary array. Using that, this patch *drastically* simplifies the IR generation of this construct, provides IR generation support for nested global initializer_list objects, fixes several bugs where the destructors for the underlying array would accidentally not get invoked, and provides constant expression evaluation support for std::initializer_list objects. llvm-svn: 183872
* Recursively lifetime-extend into array temporaries. These can get implicitlyRichard Smith2013-06-081-0/+6
| | | | | | created through binding a reference-to-array to an initializer list. llvm-svn: 183594
* When a static storage duration temporary appears in a constant expression, itRichard Smith2013-06-061-0/+10
| | | | | | | | must be initialized by a constant expression (not just a core constant expression), because we're going to emit it as a global. Core issue for this is pending. llvm-svn: 183388
* Model temporary lifetime-extension explicitly in the AST. Use this model toRichard Smith2013-06-051-3/+42
| | | | | | | | | handle temporaries which have been lifetime-extended to static storage duration within constant expressions. This correctly handles nested lifetime extension (through reference members of aggregates in aggregate initializers) but non-constant-expression emission hasn't yet been updated to do the same. llvm-svn: 183283
* Refactor constant expression evaluation to associate the complete object of aRichard Smith2013-06-031-4/+9
| | | | | | | | | | | | | | materialized temporary with the corresponding MaterializeTemporaryExpr. This is groundwork for providing C++11's guaranteed static initialization for global references bound to lifetime-extended temporaries (if the initialization is a constant expression). In passing, fix a couple of bugs where some evaluation failures didn't trigger diagnostics, and a rejects-valid where potential constant expression testing would assume that it knew the dynamic type of *this and would reject programs which relied on it being some derived type. llvm-svn: 183093
* PR14772: Support constant expression evaluation for _Atomic types.Richard Smith2013-05-231-0/+25
| | | | | | | | | * Treat _Atomic(T) as a literal type if T is a literal type. * Evaluate expressions of this type properly. * Fix a lurking bug where we built completely bogus ASTs for converting to _Atomic types in C++ in some cases, caught by the tests for this change. llvm-svn: 182541
* Suppress bogus "use of undefined constexpr function" error if the function bodyRichard Smith2013-05-141-0/+8
| | | | | | was erroneous and got discarded. llvm-svn: 181758
* Handle parens properly when initializing a char array from a string literal.Richard Smith2013-05-051-0/+13
| | | | llvm-svn: 181159
* PR15884: In the 'taking the address of a temporary' extension, materialize theRichard Smith2013-05-011-0/+10
| | | | | | | | temporary to an lvalue before taking its address. This removes a weird special case from the AST representation, and allows the constant expression evaluator to deal with it without (broken) hacks. llvm-svn: 180866
* C++1y: support simple variable assignments in constexpr functions.Richard Smith2013-04-261-5/+5
| | | | llvm-svn: 180603
* C++1y constexpr extensions, round 1: Allow most forms of declaration andRichard Smith2013-04-221-0/+7
| | | | | | | | statement in constexpr functions. Everything which doesn't require variable mutation is also allowed as an extension in C++11. 'void' becomes a literal type to support constexpr functions which return 'void'. llvm-svn: 180022
* Fix array constant expression evaluation bug: we can have different values forRichard Smith2013-04-221-0/+18
| | | | | | | different array elements, even if they're all constructed using the same default constructor. llvm-svn: 180017
* The 'constexpr implies const' rule for non-static member functions is gone inRichard Smith2013-04-211-13/+13
| | | | | | | | | C++1y, so stop adding the 'const' there. Provide a compatibility warning for code relying on this in C++11, with a fix-it hint. Update our lazily-written tests to add the const, except for those ones which were testing our implementation of this rule. llvm-svn: 179969
OpenPOWER on IntegriCloud