Commit Graph

2353 Commits

Author SHA1 Message Date
Hans Wennborg cb9ad9908b Move TLS check from LValueExprEvaluator::VisitVarDecl to
CheckLValueConstantExpression.

Richard pointed out that using the address of a TLS variable is ok in a
core C++11 constant expression, as long as it isn't part of the eventual
result of constant expression evaluation. Having the check in
CheckLValueConstantExpression accomplishes this.

llvm-svn: 162850
2012-08-29 18:27:29 +00:00
Hans Wennborg 2efa2c33ec Fix r162835 as per Richard's comments.
VisitVarDecl should return Error(E), and we should test that the address
of a TLS var can't be used as a constexpr.

llvm-svn: 162837
2012-08-29 09:17:34 +00:00
Hans Wennborg f4ad232921 Warn about suspicious implicit conversions from floating point to bool
This warns in two specific situations:

1) For potentially swapped function arguments, e.g.

     void foo(bool, float);
     foo(1.7, false);

2) Misplaced brackets around function call arguments, e.g.

     bool InRange = fabs(a - b < delta);

   Where the last argument in a function call is implicitly converted
   from bool to float, and the function returns a float which gets
   implicitly converted to bool.

Patch by Andreas Eckleder!

llvm-svn: 162763
2012-08-28 15:44:30 +00:00
Chad Rosier de70e0ef45 [ms-inline asm] As part of a larger refactoring, rename AsmStmt to GCCAsmStmt.
No functional change intended.

llvm-svn: 162632
2012-08-25 00:11:56 +00:00
Rafael Espindola 0c6c405e23 Merge existing attributes before processing pragmas in friend template
declarations.
Fixes pr13662.

llvm-svn: 162360
2012-08-22 14:52:14 +00:00
Sam Panzer 0f38443616 Better diagnostics for range-based for loops with bad range types.
The old error message stating that 'begin' was an undeclared identifier
is replaced with a new message explaining that the error is in the range
expression, along with which of the begin() and end() functions was
problematic if relevant.

Additionally, if the range was a pointer type or defines operator*,
attempt to dereference the range, and offer a FixIt if the modified range
works.

llvm-svn: 162248
2012-08-21 00:52:01 +00:00
DeLesley Hutchins f1150d3a16 Thread-safety analysis: fix scoping issues related to 'this', including an
ICE in friend functions.

llvm-svn: 162229
2012-08-20 21:32:18 +00:00
Hans Wennborg d799a2b3b9 Better wording for reference self-initialization warning.
llvm-svn: 162198
2012-08-20 08:52:22 +00:00
Richard Smith 4f605aff7f PR41111, PR5925, PR13210: Teach tentative parsing to annotate identifiers and
nested names as id-expressions, using the annot_primary_expr annotation, where
possible. This removes some redundant lookups, and also allows us to
typo-correct within tentative parsing, and to carry on disambiguating past an
identifier which we can determine will fail lookup as both a type and as a
non-type, allowing us to disambiguate more declarations (and thus offer
improved error recovery for such cases).

This also introduces to the parser the notion of a tentatively-declared name,
which is an identifier which we *might* have seen a declaration for in a
tentative parse (but only if we end up disambiguating the tokens as a
declaration). This is necessary to correctly disambiguate cases where a
variable is used within its own initializer.

llvm-svn: 162159
2012-08-18 00:55:03 +00:00
Hans Wennborg e1fdb059c6 Warn about self-initialization of references.
Initializing a reference with itself, e.g. "int &a = a;" seems like a
very bad idea.

llvm-svn: 162093
2012-08-17 10:12:33 +00:00
Richard Smith 034b94a557 Don't forget to apply #pragma pack to partial and explicit specializations of
class templates. This fixes misalignment issues in llvm/Support/Endian.h when
built by Clang.

llvm-svn: 162074
2012-08-17 03:20:55 +00:00
DeLesley Hutchins 19c722d61d Thread safety analysis: prevent a compiler error in cases where a
late-parsed attribute is attached to an invalid declaration.

llvm-svn: 161997
2012-08-15 22:41:04 +00:00
Richard Trieu b7ed89eb94 Check local static variables for self reference on initialization.
llvm-svn: 161909
2012-08-14 23:50:52 +00:00
Eli Friedman 1d4c3cfb88 Make __is_convertible_to handle abstract types correctly. PR13591.
llvm-svn: 161828
2012-08-14 02:06:07 +00:00
DeLesley Hutchins 0c90c2bc4b Thread-safety-analysis: adds existential quantification over lock
expressions.  The syntax &MyClass::mutex is interpreted as a
pattern that matches m->mutex for any object m of type MyClass.

llvm-svn: 161691
2012-08-10 20:29:46 +00:00
DeLesley Hutchins 9b1d72f3e3 Thread safety analysis: refactor to support more sophisticated handling
of expressions, and better error messages.

llvm-svn: 161690
2012-08-10 20:19:55 +00:00
Eli Friedman 971bfa11c6 Unify the codepaths for emitting deprecation warnings. The test changes are just to account for us emitting notes more consistently.
llvm-svn: 161528
2012-08-08 21:52:41 +00:00
David Blaikie 1c7c8f7637 Implement warning for integral null pointer constants other than the literal 0.
This is effectively a warning for code that violates core issue 903 & thus will
become standard error in the future, hopefully. It catches strange null
pointers such as: '\0', 1 - 1, const int null = 0; etc...

There's currently a flaw in this warning (& the warning for 'false' as a null
pointer literal as well) where it doesn't trigger on comparisons (ptr == '\0'
for example). Fix to come in a future patch.

Also, due to this only being a warning, not an error, it triggers quite
frequently on gtest code which tests expressions for null-pointer-ness in a
SFINAE context (so it wouldn't be a problem if this was an error as in an
actual implementation of core issue 903). To workaround this for now, the
diagnostic does not fire in unevaluated contexts.

Review by Sean Silva and Richard Smith.

llvm-svn: 161501
2012-08-08 17:33:31 +00:00
Richard Smith f2b084fc5a Implement final piece of DR963 and also DR587:
A conditional operator between glvalues of types cv1 T and cv2 T produces a
glvalue if the expressions are of the same value kind and one of cv1 and cv2
is a subset of the other.

A conditional operator between two null pointer constants is permitted if one
of them is of type std::nullptr_t.

llvm-svn: 161476
2012-08-08 06:13:49 +00:00
Eli Friedman ecffd83c85 Get rid of an early return in Sema::ActOnFields which doesn't make sense anymore.
Fixes a crash (<rdar://problem/11067144>), and generally seems to improve
recovery in other cases.

llvm-svn: 161474
2012-08-08 04:39:56 +00:00
Richard Smith 45edb704d3 When building a conditional operator where one operand is a throw-expression
and the other is a glvalue of class type, don't forget to copy-initialize a
temporary when performing the lvalue-to-rvalue conversion on the glvalue.
Strangely, DefaultLvalueConversions misses this part of the lvalue-to-rvalue
conversions.

llvm-svn: 161450
2012-08-07 22:06:48 +00:00
Richard Smith 0a8cfc79b7 -Wunused-private-fields: Don't try to check unresolved initializer expressions
for side-effects. Instead, check for side-effects after performing
initialization. Doing so also removes some strange corner cases and differences
between in-class initialization and constructor initialization.

llvm-svn: 161449
2012-08-07 21:30:42 +00:00
Richard Trieu 43803f0951 For global record types, the self reference checker was called twice, resulting
in duplicate -Wuninitialized warnings.  Change so that only the check in
TryConstructorInitialization() will be used and a single warning be emitted.

llvm-svn: 161345
2012-08-06 21:09:23 +00:00
Richard Smith f716bb859b PR13527: don't assert if a function is explicitly defaulted when it's already
been defined.

llvm-svn: 161315
2012-08-06 02:25:10 +00:00
Richard Smith ed9430274e Fix crash if a literal operator template's template parameter pack is not a non-type template parameter pack. Patch by Andy Gibbs!
llvm-svn: 161260
2012-08-03 21:14:57 +00:00
Aaron Ballman 899b9c6666 Explicitly defaulted constructors cannot be used for default initialization.
llvm-svn: 161088
2012-07-31 22:40:31 +00:00
Douglas Gregor f4cc61d525 When testing whether we can perform copy or move initialization, be
sure to supply an initialization location. Fixes <rdar://problem/11951661>.

llvm-svn: 161084
2012-07-31 22:15:04 +00:00
Sylvestre Ledru a5202660fb Fix some minor typos
llvm-svn: 161036
2012-07-31 06:56:50 +00:00
Richard Smith 711ceba5ab Extend the ',' versus ';' diagnostic for -Wvexing-parse to cover the with-arguments case as well as the no-arguments case.
llvm-svn: 160999
2012-07-30 21:42:05 +00:00
Richard Smith 943c440455 Improvements to vexing-parse warnings. Make the no-parameters case more
accurate by asking the parser whether there was an ambiguity rather than trying
to reverse-engineer it from the DeclSpec. Make the with-parameters case have
better diagnostics by using semantic information to drive the warning,
improving the diagnostics and adding a fixit.

Patch by Nikola Smiljanic. Some minor changes by me to suppress diagnostics for
declarations of the form 'T (*x)(...)', which seem to have a very high false
positive rate, and to reduce indentation in 'warnAboutAmbiguousFunction'.

llvm-svn: 160998
2012-07-30 21:30:52 +00:00
Benjamin Kramer e3895eb050 Use the location of the copy assignment when diagnosing classes that are nontrivial because of it.
llvm-svn: 160962
2012-07-30 16:41:40 +00:00
Benjamin Kramer bc7dd9ea02 Fix ambiguity detection in GetBestOverloadCandidateSimple.
When performing the simplistic overload resolution for single-argument methods,
don't check the best overload for ambiguity with itself when the best overload
doesn't happen to be the first one.

Fixes PR13480.

llvm-svn: 160961
2012-07-30 15:53:26 +00:00
Richard Smith f86b0ae196 PR13433: In Microsoft mode, don't require function calls within decltype
expressions to have complete return types (or accessible destructors). If the
return type is required to be complete for some other reason (for instance, if
it is needed by overload resolution), then it will still be required to be
complete. This is apparently required in order to parse a MSVC11 header.

llvm-svn: 160924
2012-07-28 19:54:11 +00:00
Benjamin Kramer a2dcac1095 Fix PR13394: Erasing from a vector changes the end of the vector, so make sure we always have the right end.
llvm-svn: 160855
2012-07-27 10:21:08 +00:00
Richard Smith d3b5c90865 Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).

EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.

This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.

The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.

Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).

llvm-svn: 160847
2012-07-27 04:22:15 +00:00
Richard Smith 2589b9808e PR12057: Allow variadic template pack expansions to cross lambda boundaries.
Rather than adding a ContainsUnexpandedParameterPack bit to essentially every
AST node, we tunnel the bit directly up to the surrounding lambda expression
when we reach a context where an unexpanded pack can not normally appear.
Thus any statement or declaration within a lambda can now potentially contain
an unexpanded parameter pack.

llvm-svn: 160705
2012-07-25 03:56:55 +00:00
Hans Wennborg 84ce606b91 Tweak warning text for returning incomplete type from extern "C" functions.
A warning was added in r150128 for returning non-C compatible
user-defined types from functions with C linkage.

This makes the text more clear for the case when the type isn't
decidedly non-C compatible, but incomplete.

llvm-svn: 160681
2012-07-24 17:59:41 +00:00
Francois Pichet f5b24e0136 Allow the parser to recover gracefully if a typename is used to introduce a decltype type.
In Microsoft mode, we emit a warning instead of an error.

This fixes a couple of errors when parsing the MSVC 11 RC headers with clang.

llvm-svn: 160613
2012-07-22 15:10:57 +00:00
Francois Pichet 0e2b84312f char16_t and char32_t are defined via typedef in MSVC 11 RC. So introduce a way to disable keywords under Microsoft mode.
llvm-svn: 160612
2012-07-22 11:32:41 +00:00
Aaron Ballman 9bca21ed25 No longer assuming the number of prototype arguments is always less than the number of formal parameters for a variadic function call.
llvm-svn: 160570
2012-07-20 20:40:35 +00:00
Nico Weber 9035951409 Let Expr::HasSideEffects() return false for NULL, bool literals, this, and nullptr.
Fixes PR13413, -Wunused-private-field now warns on unused fields initialized to NULL.

llvm-svn: 160541
2012-07-20 03:39:05 +00:00
Nico Weber 55a952bfcf Rename warn-unused-member.cpp to warn-unused-private-field.cpp to
make it match the flag it tests.

llvm-svn: 160536
2012-07-20 01:42:44 +00:00
Jordan Rose 3e0ec58c09 For varargs, diagnose passing ObjC objects by value like other non-POD types.
While we still want to consider this a hard error (non-POD variadic args are
normally a DefaultError warning), delaying the diagnostic allows us to give
better error messages, which also match the usual non-POD errors more closely.

In addition, this change improves the diagnostic messages for format string
argument type mismatches by passing down the type of the callee, so we can
say "variadic method" or "variadic function" appropriately.

<rdar://problem/11825593>

llvm-svn: 160517
2012-07-19 18:10:23 +00:00
Argyrios Kyrtzidis ac4cdc8ef4 Add a test case for rdar://11806334.
Makes sure we don't overflow the stack.

llvm-svn: 160511
2012-07-19 16:08:28 +00:00
Aaron Ballman 24a1047c8c Relaxed enumeration constant naming rules for scoped enumerators so they no longer emit a diagnostic when the enumeration's name matches that of the class. Fixes PR13128.
llvm-svn: 160490
2012-07-19 03:12:23 +00:00
Eli Friedman ea90a40339 Fix test so it works the same way on 32-bit and 64-bit.
llvm-svn: 160415
2012-07-18 01:03:11 +00:00
Eli Friedman 4eafb6b77b Don't treat overflow in floating-point conversions as a hard error in constant evaluation. <rdar://problem/11874571>.
llvm-svn: 160394
2012-07-17 21:03:05 +00:00
Rafael Espindola 60a2bba976 Handle the case where the base type is not dependent, but the derived one is.
Fixes pr13353.cpp.

llvm-svn: 160393
2012-07-17 20:24:05 +00:00
Richard Smith 6376d1fd9c -Wuninitialized: Split the classification of DeclRefExprs as initialization or
use out of TransferFunctions, and compute it in advance rather than on-the-fly.

This allows us to handle compound assignments with DeclRefExprs on the RHS
correctly, and also makes it trivial to treat const& function parameters as not
initializing the argument. The patch also makes both of those changes.

llvm-svn: 160330
2012-07-17 00:06:14 +00:00
David Blaikie 5a0956e98d Fix rejects-valid: explicit specialization of redeclared deleted function template.
Review by Richard Smith.

llvm-svn: 160306
2012-07-16 18:50:45 +00:00