summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Sema] Make `&function_with_enable_if_attrs` an errorGeorge Burgess IV2015-10-121-1/+3
| | | | | | | | | | | | | | | | | | This fixes a bug where one can take the address of a conditionally enabled function to drop its enable_if guards. For example: int foo(int a) __attribute__((enable_if(a > 0, ""))); int (*p)(int) = &foo; int result = p(-1); // compilation succeeds; calls foo(-1) Overloading logic has been updated to reflect this change, as well. Functions with enable_if attributes that are always true are still allowed to have their address taken. Differential Revision: http://reviews.llvm.org/D13607 llvm-svn: 250090
* [Sema] Don't create an invalid source range for overlong initializer lists.Benjamin Kramer2015-09-231-2/+4
| | | | | | | | | We took both source locations from the end of the initializer list what the code below doesn't expect. This can lead to a crash when rendering the diagnostic (PR24816). Assert that we have more than one element in a scalar initializer with too many elements. llvm-svn: 248391
* Clarify the error message when the reason the conversion is not viable is ↵Nick Lewycky2015-08-251-0/+1
| | | | | | because the returned value does not match the function return type. llvm-svn: 245979
* [Sema] Don't crash when diagnosing hack in libstdc++David Majnemer2015-08-211-2/+5
| | | | | | | | | | | | While working around a bug in certain standard library implementations, we would try to diagnose the issue so that library implementors would fix their code. However, we assumed an entity being initialized was a non-static data member subobject when other circumstances are possible. This fixes PR24526. llvm-svn: 245675
* Fix -Wredundant-move warning.Richard Trieu2015-07-291-30/+3
| | | | | | | | | Without DR1579 implemented, the only case for -Wredundant-move is for a parameter being returned with the same type as the function return type. Also include a check to verify that the move constructor will be used by matching nodes in the AST dump. llvm-svn: 243594
* Disable -Wpessimizing-move and -Wredundant-move in template instantiations.Richard Trieu2015-07-291-0/+3
| | | | | | | | | Dependent types can throw off the analysis for these warnings, possibly giving conflicting warnings and fix-its. Disabling the warning in template instantiations will prevent this problem, and will still catch the non-dependent cases in templates. llvm-svn: 243538
* Do not give a -Wredundant-move warning when removing the move will result in anRichard Trieu2015-07-281-1/+11
| | | | | | | | | error. If the object being moved has a move constructor and a deleted copy constructor, std::move is required, otherwise Clang will give a deleted constructor error. llvm-svn: 243463
* [sema] Fix infinite loop when using a boolean value as designated initializer.Argyrios Kyrtzidis2015-07-271-8/+6
| | | | | | | For designated indices use the max array size type bitwidth, not the bitwidth of the index value itself. rdar://21942503 llvm-svn: 243343
* [Sema] Emit correct warning when copy-elision is not possible.Davide Italiano2015-07-181-0/+5
| | | | | | | | | | If we're returning a function parameter, copy elision isn't possible, so we now warn for redundant move. PR: 23819 Differential Revision: http://reviews.llvm.org/D11305 llvm-svn: 242600
* [Sema] Range-loopify InititializationSequence destructor. NFC intended.Davide Italiano2015-07-011-4/+2
| | | | llvm-svn: 241195
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-1/+1
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-1/+1
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao2015-06-101-38/+194
| | | | | | | | | | | | | | | | | | | | | | | | | Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
* Have -Wredundant-move ignore reference types.Richard Trieu2015-05-181-0/+3
| | | | | | | Don't give a warning when the type being moved is a reference type. Also uncomment two lines in the test case. llvm-svn: 237607
* When emitting a dropped qualifier error, show which qualifiers are dropped.Richard Trieu2015-05-161-3/+10
| | | | llvm-svn: 237505
* Reverse the order of types in the reference dropping qualifiers error.Richard Trieu2015-05-151-1/+1
| | | | | | | | The error has the form ... 'int' ... 'const int' ... dropped qualifiers. At first glance, it appears that the const qualifier is added. Reverse the types so that the second type is less qualified than the first. llvm-svn: 237482
* Add -Wpessimizing-move and -Wredundant-move warnings.Richard Trieu2015-04-291-0/+112
| | | | | | | | | | | | | | | -Wpessimizing-move warns when a call to std::move would prevent copy elision if the argument was not wrapped in a call. This happens when moving a local variable in a return statement when the variable is the same type as the return type or using a move to create a new object from a temporary object. -Wredundant-move warns when an implicit move would already be made, so the std::move call is not needed, such as when moving a local variable in a return that is different from the return type. Differential Revision: http://reviews.llvm.org/D7633 llvm-svn: 236075
* [Sema] Do not permit binding a reference to a compound literalDavid Majnemer2015-04-261-0/+5
| | | | | | | | | We could probably make this work if we cared enough. However, we are far outside any language rules at this point. This fixes PR21834. llvm-svn: 235818
* Move fixit for const init from note to diag, weaken to warning in MS mode.Nico Weber2015-04-171-23/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove useless statement.Nikola Smiljanic2015-04-141-1/+0
| | | | llvm-svn: 234881
* [Sema] Don't assume that an initializer list has an initializerDavid Majnemer2015-04-101-3/+3
| | | | | | | | Given something like 'int({}, 1)', we would try to emit a diagnostic regarding the excess element in the scalar initializer. However, we assumed that the initializer list had an element in it. llvm-svn: 234565
* Fix UTF8 chars to ASCII.NAKAMURA Takumi2015-02-251-2/+2
| | | | llvm-svn: 230479
* Revert r167816 and replace it with a proper fix for the issue: do notRichard Smith2015-02-211-17/+4
| | | | | | | invalidate lookup_iterators and lookup_results for some name within a DeclContext if the lookup results for a *different* name change. llvm-svn: 230121
* DR1467: If aggregate initialization encounters an initializer list for whichRichard Smith2015-02-161-1/+2
| | | | | | | | subobject initialization is not possible, be sure to note the overall initialization as having failed so that overload resolution knows that the relevant candidate is not viable. llvm-svn: 229353
* More for DR1467: In C++, when initializing an element of an aggregate,Richard Smith2015-02-121-39/+40
| | | | | | | | | always use the normal copy-initialization rules. Remove a special case that tries to stay within the list initialization checker here; that makes us do the wrong thing when list-initialization of an aggregate would not perform aggregate initialization. llvm-svn: 228897
* Improve the "braces around scalar init" warning to determine whether to warnRichard Smith2015-02-121-6/+65
| | | | | | | | based on whether "redundant" braces are ever reasonable as part of the initialization of the entity, rather than whether the initialization is "top-level". In passing, add a warning flag for it. llvm-svn: 228896
* A temporary fix for backward compatibility breakages caused by PR12117.Larisse Voufo2015-02-101-4/+15
| | | | llvm-svn: 228654
* Update APIs that return a pair of iterators to return an iterator_range instead.Benjamin Kramer2015-02-061-10/+5
| | | | | | Convert uses of those APIs into ranged for loops. NFC. llvm-svn: 228404
* Fix \param in r228276. [-Wdocumentation]NAKAMURA Takumi2015-02-051-1/+1
| | | | llvm-svn: 228355
* PR22465: when performing list-initialization for a class type C, if we see anRichard Smith2015-02-051-16/+19
| | | | | | | | | | initializer of the form {x}, where x is of type C or a type derived from C, perform *non-list* initialization of the entity from x, but create a CXXConstructExpr that knows that we used list-initialization syntax. Plus some fixes to ensure we mangle correctly in this and related cases. llvm-svn: 228276
* Various fixes to mangling of list-initialization.Richard Smith2015-02-051-0/+3
| | | | llvm-svn: 228274
* CXX [qoi]. Prevent a crash when initializer expression isFariborz Jahanian2015-01-281-0/+2
| | | | | | | invalid when trying to create temporary copy of the invalid initializer. rdar://19109967 llvm-svn: 227378
* Implement the remaining portion of DR1467 from r227022. I may have ↵Larisse Voufo2015-01-271-33/+14
| | | | | | overlooked a few things, but this implementation comes straight from the DR resolution itself. llvm-svn: 227224
* Tweak r227115 per review feedbackBen Langmuir2015-01-261-1/+1
| | | | | | | Use getAsArrayTypeUnsafe() instead of getUnqualifiedDesugaredType() to get the underlying ArrayType. llvm-svn: 227129
* Fix assert instantiating string init of static variableBen Langmuir2015-01-261-3/+3
| | | | | | | | ... when the variable's type is a typedef of a ConstantArrayType. Just look through the typedef (and any other sugar). We only use the constant array type here to get the element count. llvm-svn: 227115
* Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed().Nico Weber2015-01-261-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | clang currently calls MarkVTableUsed() for classes that get their virtual methods called or that participate in a dynamic_cast. This is unnecessary, since CodeGen only emits vtables when it generates constructor, destructor, and vtt code. (*) Note that Sema::MarkVTableUsed() doesn't cause the emission of a vtable. Its main user-visible effect is that it instantiates virtual member functions of template classes, to make sure that if codegen decides to write a vtable all the entries in the vtable are defined. While this shouldn't change the behavior of codegen (other than being faster), it does make clang more permissive: virtual methods of templates (in particular destructors) end up being instantiated less often. In particular, classes that have members that are smart pointers to incomplete types will now get their implicit virtual destructor instantiated less frequently. For example, this used to not compile but does now compile: template <typename T> struct OwnPtr { ~OwnPtr() { static_assert((sizeof(T) > 0), "TypeMustBeComplete"); } }; class ScriptLoader; struct Base { virtual ~Base(); }; struct Sub : public Base { virtual void someFun() const {} OwnPtr<ScriptLoader> m_loader; }; void f(Sub *s) { s->someFun(); } The more permissive behavior matches both gcc (where this is not often observable, since in practice most things with virtual methods have a key function, and Sema::DefineUsedVTables() skips vtables for classes with key functions) and cl (which is my motivation for this change) – this fixes PR20337. See this issue and the review thread for some discussions about optimizations. This is similar to r213109 in spirit. r225761 was a prerequisite for this change. Various tests relied on "a->f()" marking a's vtable as used (in the sema sense), switch these to just construct a on the stack. This forces instantiation of the implicit constructor, which will mark the vtable as used. (*) The exception is -fapple-kext mode: In this mode, qualified calls to virtual functions (`a->Base::f()`) still go through the vtable, and since the vtable pointer off this doesn't point to Base's vtable, this needs to reference Base's vtable directly. To keep this working, keep referencing the vtable for virtual calls in apple kext mode. llvm-svn: 227073
* First steps in implementing DR1467: List-initialization of aggregate from ↵Larisse Voufo2015-01-241-32/+92
| | | | | | | | | | same-type object. Only the first two items for now, changing Sections 8.5.4 [dcl.init.list] paragraph 3 and 13.3.1.7 [over.match.list] paragraph 1, so that defining class objects and character arrays using uniform initialization syntax is actually treated as list initialization and before it is treated aggregate initialization. llvm-svn: 227022
* Fix temporary lifetime extension from an initializer using braced "functional"Richard Smith2015-01-101-7/+7
| | | | | | cast notation T{...} when T is a reference type. llvm-svn: 225571
* Handle use of default member initializers before end of outermost classReid Kleckner2014-11-171-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 brace init of unions with unnamed struct membersReid Kleckner2014-11-121-2/+3
| | | | | | | | The check for unnamed members was intended to skip unnamed bitfields, but it ended up skipping unnamed structs. This lead to an assertion in IRGen. llvm-svn: 221818
* Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata2014-10-271-2/+2
| | | | | | TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
* PR20844: If we fail to list-initialize a reference, map to the referenced typeRichard Smith2014-09-041-0/+13
| | | | | | | | | before retrying the initialization to produce diagnostics. Otherwise, we may fail to produce any diagnostics, and silently produce invalid AST in a -Asserts build. Also add a note to this codepath to make it more clear why we were trying to create a temporary. llvm-svn: 217197
* CodeGen: Skip unnamed bitfields when handling designated initializersDavid Majnemer2014-08-231-1/+9
| | | | | | | We would accidently initialize unnamed bitfields instead of the following field. llvm-svn: 216313
* Sema: Properly perform lookup when acting on fields for desig initsDavid Majnemer2014-08-111-88/+35
| | | | | | | | | | | | | | | | | | | | Clang used a custom implementation of lookup when handling designated initializers. The custom code was not particularly optimized and relied on standard lookup for typo-correction anyway. This custom code has to go, it doesn't properly support MSVC-style anonymous structs embedded inside other records; replace it with the typo-correction path. This has the side effect of speeding up semantic handling of the fields for a designated initializer while simplifying the code at the same time. This fixes PR20573. Differential Revision: http://reviews.llvm.org/D4839 llvm-svn: 215372
* PR18097: Support initializing an _Atomic(T) from an object of C++ class type TRichard Smith2014-07-311-12/+43
| | | | | | | or a class derived from T. We already supported this when initializing _Atomic(T) from T for most (and maybe all) other reasonable values of T. llvm-svn: 214390
* Improve diagnostic on default-initializing const variables (PR20208).Nico Weber2014-07-231-1/+22
| | | | | | | | 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
* PR20356: Fix all Sema warnings with mismatched ext_/warn_ versusRichard Smith2014-07-191-3/+3
| | | | | | | | ExtWarn/Warnings. Mostly the name of the warning was changed to match the semantics, but in the PR20356 cases, the warning was about valid code, so the diagnostic was changed from ExtWarn to Warning instead. llvm-svn: 213443
* Cleanup: remove essentially unused variable.Richard Smith2014-07-181-3/+2
| | | | llvm-svn: 213347
* SemaInit.cpp: Fix a warning with -Asserts. [-Wunused-variable]NAKAMURA Takumi2014-07-181-0/+1
| | | | llvm-svn: 213345
* PR20346: fix aggregate initialization / template instantiation bug:Richard Smith2014-07-171-0/+9
| | | | | | | | | | | | | If, during the initial parse of a template, we perform aggregate initialization and form an implicit value initialization for an array type, then when we come to instantiate the template and redo the initialization step, we would try to match the implicit value initialization up against an array *element*, not to the complete array. Remarkably, we've had this bug since ~the dawn of time, but only noticed it recently. llvm-svn: 213332
OpenPOWER on IntegriCloud