summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX
Commit message (Collapse)AuthorAgeFilesLines
* Do not parse members of incomplete class.Serge Pavlov2015-06-101-0/+12
| | | | | | | | | | If definition of a class is unknown and out-of-line definition of its member is encountered, do not parse the member declaration. This change fixes PR18542. Differential Revision: http://reviews.llvm.org/D8010 llvm-svn: 239483
* Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao2015-06-101-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* [MSVC Compatibility] Don't diagnose c-style cast from void-ptr to fn-ptrDavid Majnemer2015-06-091-1/+5
| | | | | | | | The machinery added to permit a static_cast from void-ptr to fn-ptr unintentionally gets triggered for c-style casts and function-style casts. The observable effect was a diagnostic issued inappropriately. llvm-svn: 239382
* Enable propagation of dll attributes to previously instantiated base class ↵Hans Wennborg2015-06-092-10/+18
| | | | | | | | | | | | | | | templates in some cases It is safe to add a dll attribute if the base class template previously only had an explicit instantiation declaration, or was implicitly instantiated. I both those cases, the members would not have been codegenned yet. In the case of explicit instantiation declaration this is natural, and for implicit instantiations, codegen is deferred (see r225570). This is work towards fixing PR23770. llvm-svn: 239373
* Narrow the -Wunsupported-dll-base-class-template warning.Hans Wennborg2015-06-092-14/+6
| | | | | | | | | | | | | Don't warn about not being able to propagate dll attribute to a base class template when that base already has a different attribute. MSVC doesn't actually try to do this; the first attribute that was propagated takes precedence, so Clang is already doing the right thing and there's no need to warn. (This is a step towards fixing PR21718.) llvm-svn: 239372
* Move a test from static-assert.cpp to DeclPrinterTestDavid Majnemer2015-06-051-9/+0
| | | | | | | | It's better not to rely on the diagnostics engine to pretty print the argument to decltype. Instead, exercise the functionality in DeclPrinterTest. llvm-svn: 239197
* [AST] There is no message for C++1z-style static_assertDavid Majnemer2015-06-051-0/+9
| | | | | | | | | | We would crash in the DeclPrinter trying to pretty-print the static_assert message. C++1z-style assertions don't have a message so we would crash. This fixes PR23756. llvm-svn: 239170
* [MSVC Compatibility] Permit static_cast from void-ptr to function-ptrDavid Majnemer2015-06-021-0/+2
| | | | | | | | | | | The MSVC 2013 and 2015 implementation of std::atomic is specialized for pointer types. The member functions are implemented using a static_cast from void-ptr to function-ptr which is not allowed in the standard. Permit this conversion if -fms-compatibility is present. This fixes PR23733. llvm-svn: 238877
* Fix assertion on C++ attributes in fillAttributedTypeLocAlexander Musman2015-05-291-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | this fixes http://llvm.org/PR17424 fillAttributedTypeLoc() function is only called with AttributeLists of either DeclarationChunk (which is used for each type in a declarator being parsed) or DeclSpec (which captures information about declaration specifiers). As C++11 attributes actually appertain to declarators, they are moved straight to the declarator’s attr list in distributeFunctionTypeAttrFromDeclSpec() function. 'Put them wherever you like' semantics is not supported for C++11 attributes (but is allowed for GNU attributes, for example). So when we meet an attribute while parsing the declaration, we cannot be sure if it appertains to either DeclarationChunk or DeclSpec. This investigation correlates with the history of changes of SemaType.cpp: • Asserts in fillAttributedTypeLoc() were added on 3 Mar 2011 in r126986 (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon- 20110228/039638.html); • Distributing C++11 attrs to the declarator was added on 14 Jan 2013 in r172504 (http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon- 20130114/071830.html). Considering all written above I changed asserts in fillAttributedTypeLoc() to nullptr checks. This fixes PR17424 and related assertion on [[gnu::fastcall]] void __stdcall foo(); Author: Alexey Frolov Differential Revision: http://reviews.llvm.org/D9288 llvm-svn: 238550
* Update -Winvalid-noreturn to handle destructors better.Richard Trieu2015-05-281-0/+148
| | | | | | | | | | When checking if a function is noreturn, consider a codepath to be noreturn if the path destroys a class and the class destructor, base class destructors, or member field destructors are marked noreturn. Differential Revision: http://reviews.llvm.org/D9454 llvm-svn: 238382
* __declspec is not a core Clang language extension. Instead, require ↵Aaron Ballman2015-05-264-13/+13
| | | | | | | -fms-extensions or -fborland to enable the language extension. Note: __declspec is also temporarily enabled when compiling for a CUDA target because there are implementation details relying on __declspec(property) support currently. When those details change, __declspec should be disabled for CUDA targets. llvm-svn: 238238
* PR20073: promote "dereference of 'void*'" from Extension to ExtWarn.Richard Smith2015-05-191-5/+5
| | | | llvm-svn: 237652
* Detect uses of mismatching forms of 'new' and 'delete'Ismail Pazarbasi2015-05-182-5/+141
| | | | | | | | | | | | | | | | | Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. rev 2 update: `getNewExprFromInitListOrExpr` should return `dyn_cast_or_null` instead of `dyn_cast`, since `E` might be null. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237608
* Have -Wredundant-move ignore reference types.Richard Trieu2015-05-181-2/+26
| | | | | | | 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
* Fix typo from r237482. "to reference of type" --> "to reference to type"Richard Trieu2015-05-162-2/+2
| | | | llvm-svn: 237507
* When emitting a dropped qualifier error, show which qualifiers are dropped.Richard Trieu2015-05-164-4/+47
| | | | llvm-svn: 237505
* clang/test/SemaCXX/attr-no-sanitize.cpp: Don't mix stdout and stderr for ↵NAKAMURA Takumi2015-05-161-2/+2
| | | | | | | | FileCheck. MSVCRT's stdio doesn't do line buffering. llvm-svn: 237492
* Reverse the order of types in the reference dropping qualifiers error.Richard Trieu2015-05-152-2/+2
| | | | | | | | 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
* Implement no_sanitize attribute.Peter Collingbourne2015-05-151-0/+29
| | | | | | Differential Revision: http://reviews.llvm.org/D9631 llvm-svn: 237463
* Revert "Detect uses of mismatching forms of 'new' and 'delete'"Diego Novillo2015-05-142-140/+5
| | | | | | | | | This reverts commit 742dc9b6c9686ab52860b7da39c3a126d8a97fbc. This is generating multiple segfaults in our internal builds. Test case coming up shortly. llvm-svn: 237391
* Detect uses of mismatching forms of 'new' and 'delete'Ismail Pazarbasi2015-05-142-5/+140
| | | | | | | | | | | | | Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237368
* Fix buildbotsDavid Majnemer2015-05-141-1/+1
| | | | llvm-svn: 237338
* [MS ABI] __declspec(thread) behaves like thread_local in MSVC 2015David Majnemer2015-05-141-2/+15
| | | | | | | MSVC 2015 changed __declspec(thread) to make it behave like C++11's thread_local keyword instead of acting similarly to __thread. llvm-svn: 237337
* Replace the broken LambdaCapture::isInitCapture API.James Dennett2015-05-071-1/+24
| | | | | | | | | | | | | | | A LambdaCapture does not have sufficient information to correctly determine whether it is an init-capture or not. Doing so requires knowledge held in the LambdaExpr itself. It the case of a nested capture of an init-capture it is not sufficient to check (as LambdaCapture::isInitCapture did) whether the associated VarDecl was from an init-capture. This patch moves isInitCapture to LambdaExpr and updates Capture->isInitCapture() to Lambda->isInitCapture(Capture). llvm-svn: 236760
* When performing delayed typo correction in a for-range loop's variableKaelyn Takata2015-05-071-0/+9
| | | | | | | declaration, ensure the loop variable is properly marked as invalid when it is an "auto" variable. llvm-svn: 236682
* Allow TransformTypos to ignore corrections to a specified VarDecl.Kaelyn Takata2015-05-051-0/+8
| | | | | | | | | | | | | This is needed to prevent a TypoExpr from being corrected to a variable when the TypoExpr is a subexpression of that variable's initializer. Also exclude more keywords from the correction candidate pool when the subsequent token is .* or ->* since keywords like "new" or "return" aren't valid on the left side of those operators. Fixes PR23140. llvm-svn: 236519
* Diagnose delayed typos when parsing a postfix expression with anKaelyn Takata2015-05-021-0/+6
| | | | | | | | unmatched l_paren before setting the LHS to ExprError(). Fixes PR23285. llvm-svn: 236371
* Also correct typos in the middle of a ternary expression when the RHS is ↵Kaelyn Takata2015-05-011-0/+5
| | | | | | | | | | | | invalid. The LHS was already being corrected before being set to ExprError when the RHS is invalid, but when it was present the middle of a ternary expression would be dropped in the error paths. Fixes PR23350. llvm-svn: 236347
* Add -Wpessimizing-move and -Wredundant-move warnings.Richard Trieu2015-04-292-0/+271
| | | | | | | | | | | | | | | -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
* Fix Sema tests using __try by adding tripleReid Kleckner2015-04-282-3/+3
| | | | llvm-svn: 236057
* Check whether the operand to a noexcept expression is valid or not. Fixes ↵Aaron Ballman2015-04-271-0/+19
| | | | | | PR15842. llvm-svn: 235931
* PR23334: Perform semantic checking of lambda capture initialization in the ↵Richard Smith2015-04-273-2/+23
| | | | | | | | | | | | | | | | | | right context. Previously we'd try to perform checks on the captures from the middle of parsing the lambda's body, at the point where we detected that a variable needed to be captured. This was wrong in a number of subtle ways. In PR23334, we couldn't correctly handle the list of potential odr-uses resulting from the capture, and our attempt to recover from that resulted in a use-after-free. We now defer building the initialization expression until we leave the lambda body and return to the enclosing context, where the initialization does the right thing. This patch only covers lambda-expressions, but we should apply the same change to blocks and captured statements too. llvm-svn: 235921
* [Sema] Do not permit binding a reference to a compound literalDavid Majnemer2015-04-261-0/+4
| | | | | | | | | 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
* [MS ABI] Fix the preferred alignment of member pointersDavid Majnemer2015-04-241-7/+7
| | | | | | | Member pointers in the MS ABI have different alignment depending on whether they were created on the stack or live in a record. llvm-svn: 235681
* Extend format specifier checking to include field function pointers in ↵Aaron Ballman2015-04-231-0/+15
| | | | | | addition to variable function pointers. Addresses PR21082. llvm-svn: 235606
* Don't dllimport/export class members with internal linkage (PR23308)Hans Wennborg2015-04-221-0/+6
| | | | | | | | | | For example, a function taking a parameter with internal linkage will itself have internal linkage since it cannot be called outside the translation unit. Differential Revision: http://reviews.llvm.org/D9182 llvm-svn: 235471
* Follow-up to r235046: selectany only causes a definition if it's not inherited.Nico Weber2015-04-171-0/+4
| | | | | | | | (For example needed to parse system header inputscope.h, which first has an extern "C" selectany IID and then later an extern "C" declaration of that same IID.) llvm-svn: 235174
* Move fixit for const init from note to diag, weaken to warning in MS mode.Nico Weber2015-04-175-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fix for PR20402 in -Wconsumed.DeLesley Hutchins2015-04-151-0/+12
| | | | | | | https://llvm.org/bugs/show_bug.cgi?id=20402 Patch by Chris Wailes. llvm-svn: 235051
* [SemaCXX patch] Patch to fix a crash when a 'delete' constructorFariborz Jahanian2015-04-141-0/+40
| | | | | | | is being accessed. Reviewed by Richard Smith. rdar://20281011 llvm-svn: 234912
* Add new warning -Wrange-loop-analysis to warn on copies during loops.Richard Trieu2015-04-131-0/+299
| | | | | | | | | | | | -Wrange-loop-analysis is a subgroup of -Wloop-analysis and will warn when a range-based for-loop makes copies of the elements in the range. If possible, suggest the proper type to prevent copies, or the non-reference to help distinguish copy versus non-copy forms. Existing warnings in -Wloop-analysis are moved to -Wfor-loop-analysis, also a subgroup of -Wloop-analysis. Differential Revision: http://reviews.llvm.org/D4169 llvm-svn: 234804
* Revert r234786, it contained a bunch of stuff I did not mean to commit.Nico Weber2015-04-131-5/+1
| | | | llvm-svn: 234787
* Revert r234613 (and follow-ups 234614, 234616, 234618), it caused PR23216.Nico Weber2015-04-131-1/+5
| | | | llvm-svn: 234786
* Improve the error message for assigning to read-only variables.Richard Trieu2015-04-116-11/+388
| | | | | | | | | | Previously, many error messages would simply be "read-only variable is not assignable" This change provides more information about why the variable is not assignable, as well as note to where the const is located. Differential Revision: http://reviews.llvm.org/D4479 llvm-svn: 234677
* Don't eagerly typo-correct to a keyword if the next token is a right paren.Kaelyn Takata2015-04-101-0/+17
| | | | | | | | | Take advantage of the delayed typo no longer being eagerly corrected to a keyword to filter out keyword corrections (and other things like unresolved & overloaded expressions, which have placeholder types) when correcting typos inside of a decltype(). llvm-svn: 234623
* [Sema] Don't assume that an initializer list has an initializerDavid Majnemer2015-04-101-2/+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
* [Sema] Diagnose references to unbound arrays in function definitionsDavid Majnemer2015-04-091-0/+3
| | | | | | | | A [*] is only allowed in a declaration for a function, not in its definition. We didn't correctly recurse on reference types while looking for it, causing us to crash in CodeGen instead of rejecting it. llvm-svn: 234528
* Properly implement warn_unused_result checking for classes/structs.Kaelyn Takata2015-04-091-2/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation would copy the attribute from the class to functions that have the class as their return type when the functions are first declared. This proved to have two flaws: 1) if the class is forward-declared without the attribute and a function or method with the class as a its return type is declared, and afterward the class is defined with warn_unused_result, the function or method would never inherit the attribute, and 2) the check simply failed for functions and methods that are part of a template instantiation, regardless of whether the class with warn_unused_result is part of a specific instantiation or part of the template itself (presumably because those function/method declaration does not hit the same code path as a non-template one and so never inherits the attribute). The new approach is to instead modify the two places where a function or method call is checked for the warn_unused_result attribute on the decl by extending the checks to also look for the attribute on the decl's return type. Additionally, the check for return types that have the warn_unused_result now excludes pointers and references to such types, as such return types do not necessarily imply a transfer of ownership for the underlying object being referred to by the return value. This does not change the behavior of functions that are directly given the warn_unused_result attribute. llvm-svn: 234526
* Generate a diagnostic when a catch handler cannot execute due to class ↵Aaron Ballman2015-04-082-4/+79
| | | | | | hierarchy inversion with regards to other catch handlers for the same block. llvm-svn: 234375
* [Sema] Don't permit dependent alignments on non-dependent typedef-namesDavid Majnemer2015-04-071-0/+13
| | | | | | | | | | | | | | | | | A dependent alignment attribute (like __attribute__((aligned(...))) or __declspec(align(...))) on a non-dependent typedef or using declaration poses a considerable challenge: the type is _not_ dependent, the size _may_ be dependent if the type is used as an array type, the alignment _is_ dependent. It is reasonable for a compiler to be able to query the size and alignment of a complete type. Let's help that become an invariant. This fixes PR22042. Differential Revision: http://reviews.llvm.org/D8693 llvm-svn: 234280
OpenPOWER on IntegriCloud