Commit Graph

1839 Commits

Author SHA1 Message Date
Lang Hames df5c121f8e Add a warning for implicit conversion from function literals (and static
methods) to bool. E.g.

void foo() {}
if (f) { ... // <- Warns here.
}

Only applies to non-weak functions, and does not apply if the function address
is taken explicitly with the addr-of operator.

llvm-svn: 145849
2011-12-05 20:49:50 +00:00
Fariborz Jahanian 5c12ca8a25 Move block return type inference diagnostic to a common place where
Function or array lvalue conversions happens.

llvm-svn: 145782
2011-12-03 23:53:56 +00:00
Douglas Gregor dca70af22f Implement support for the __is_final type trait, to determine whether
a class is marked 'final', from Alberto Ganesh Barbati! Fixes
PR11462.

llvm-svn: 145775
2011-12-03 18:14:24 +00:00
Fariborz Jahanian dd5eb9df0c If block literal return type is not specified, return type of the block is
inferred from return types. All the return statements have to agree about the type.
// rdar://10466373

llvm-svn: 145774
2011-12-03 17:47:53 +00:00
Sebastian Redl df88864273 Implement overload resolution for reference-typed parameters supplied with initializer lists.
llvm-svn: 145769
2011-12-03 14:54:30 +00:00
Ted Kremenek 85825aebc9 Further tweak -Wurneachable-code and templates by allowing the warning to run on
explicit template specializations (which represent actual functions somebody wrote).

Along the way, refactor some other code which similarly cares about whether or
not they are looking at a template instantiation.

llvm-svn: 145547
2011-12-01 00:59:17 +00:00
Ted Kremenek 7f770032c7 Don't run -Wunreachable-code on template instantiations. Different instantiations may produce different unreachable code results, and it is very difficult for us to prove that ALL instantiations of a template have specific unreachable code. If we come up with a better solution, then we can revisit this, but this approach will at least greatly reduce the noise of this warning for code that makes use of templates.
llvm-svn: 145520
2011-11-30 21:22:09 +00:00
Matt Beaumont-Gay c93b489138 Suppress -Warray-bounds for classes (not just structs) where the last field is
a 1-length character array.

llvm-svn: 145445
2011-11-29 22:43:53 +00:00
Matt Beaumont-Gay b2339826e6 Merge branch 'yo-dawg-i-herd-u-like-arrays'
llvm-svn: 145421
2011-11-29 19:27:11 +00:00
Richard Smith 675ea99a2a PR10101: Recover better from a common copy-paste error: if a function
declaration at namespace scope is followed by a semicolon and an open-brace
(or in C++, a 'try', ':' or '='), then the error is probably a function
definition with a spurious ';', rather than a mysterious '{'.

llvm-svn: 145372
2011-11-29 05:27:40 +00:00
Fariborz Jahanian 25d09c2209 pinpoint name/location of deprecated/unavailable enumerator
whose enum has been made deprecated/unavailable in the warning.
// rdar://10201690

llvm-svn: 145264
2011-11-28 19:45:58 +00:00
Sebastian Redl 29526f09ce Reference initialization with initializer lists.
This supports single-element initializer lists for references according to DR1288, as well as creating temporaries and binding to them for other initializer lists.

llvm-svn: 145186
2011-11-27 16:50:07 +00:00
Matt Beaumont-Gay 63be19122e Wordsmith the -Warray-bounds diagnostic text a bit
llvm-svn: 145116
2011-11-24 00:27:38 +00:00
Richard Trieu caff247882 Add feature to diagnostics that will provide more information on function
pointer mismatch.  Cases covered are: initialization, assignment, and function
arguments.  Additional text will give the extra information about the nature
of the mismatch: different classes for member functions, wrong number of
parameters, different parameter type, different return type, and function
qualifier mismatch.

llvm-svn: 145114
2011-11-23 22:32:32 +00:00
Richard Smith 9a56882e53 Add driver arguments -ftemplate-depth=N and -fconstexpr-depth=N, with the same
semantics and defaults as the corresponding g++ arguments. The historical g++
argument -ftemplate-depth-N is kept for compatibility, but modern g++ versions
no longer document that option.

Add -cc1 argument -fconstexpr-depth N to implement the corresponding
functionality.

The -ftemplate-depth=N part of this fixes PR9890.

llvm-svn: 145045
2011-11-21 19:36:32 +00:00
Richard Smith 027bf11eb3 Constant expression evaluation: add support for evaluation of member pointers
and base-to-derived casts, and add proper handling of temporaries.

llvm-svn: 144926
2011-11-17 22:56:20 +00:00
David Blaikie 0f65d59e52 Include named unions in union member init checking
llvm-svn: 144883
2011-11-17 06:01:57 +00:00
Abramo Bagnara dc1646dc2b Fixed plausible overloads location.
llvm-svn: 144700
2011-11-15 21:43:28 +00:00
Douglas Gregor 6c8f07ff46 Teach the CFG builder how to properly destroy temporaries who
lifetimes have been extended via reference binding. The type of the
reference and the type of the temporary are not necessarily the same,
which could cause a crash. Fixes <rdar://problem/10398199>.

llvm-svn: 144646
2011-11-15 15:29:30 +00:00
Richard Smith ce40ad677e Represent an APValue based on a Decl as that Decl, rather than a DeclRefExpr
or MemberExpr which refers to it. As a side-effect, MemberExprs which refer to
static member functions and static data members are now emitted as constant
expressions.

llvm-svn: 144468
2011-11-12 22:28:03 +00:00
Richard Smith 617940f166 Extend -Wno-bind-to-temporary-copy and -Wno-{unnamed,local}-type-template-args
to disable the corresponding -Wc++98-compat warnings in addition to the C++11
extension warnings, so that people already using these flags can switch to C++11
mode and turn on -Wc++98-compat.

llvm-svn: 144404
2011-11-11 19:29:23 +00:00
Richard Smith 6804be5a2e Constant expression evalation: const_cast support.
llvm-svn: 144382
2011-11-11 08:28:03 +00:00
Richard Smith 3ba71043dc Don't recurse so deep in this test, pending APValue rework to further reduce the
stack pressure.

llvm-svn: 144378
2011-11-11 07:10:32 +00:00
Richard Smith e97cbd7b3a Constant expression evaluation: support for constexpr member functions. This
reinstates r144273; a combination of r144333's fix for NoOp rvalue-to-lvalue
casts and some corresponding changes here resolve the regression which that
caused.

This patch also adds support for some additional forms of member function call,
along with additional testing.

llvm-svn: 144369
2011-11-11 04:05:33 +00:00
Francois Pichet f707ae6733 Move "Unqualified lookup into dependent bases of class templates" Microsoft specific behavior from -fms-extensions to -fms-compatibility.
llvm-svn: 144341
2011-11-11 00:12:11 +00:00
Devang Patel 63104ad417 Revert r144273. It causes clang self-host build failure.
llvm-svn: 144296
2011-11-10 17:47:39 +00:00
Richard Smith 656d49d890 Constant expression evaluation: support for constexpr member functions.
llvm-svn: 144273
2011-11-10 09:31:24 +00:00
Richard Smith d62306a481 Constant expression evaluation: support for evaluation of structs and unions of
literal types, as well as derived-to-base casts for lvalues and
derived-to-virtual-base casts.

llvm-svn: 144265
2011-11-10 06:34:14 +00:00
Douglas Gregor f39a8dd445 Don't crash when transforming an ill-formed pseudo-destructor
expression. Fixes PR11339.

llvm-svn: 144159
2011-11-09 02:19:47 +00:00
Richard Smith f8120cad16 Constant expression evaluation: support for default arguments.
llvm-svn: 144156
2011-11-09 02:12:41 +00:00
Richard Smith ec8dcd2716 Fix a cluster of related issues involving value-dependence and constant
expression evaluation:
 - When folding a non-value-dependent expression, we may try to use the
   initializer of a value-dependent variable. If that happens, give up.
 - In C++98, actually check that a const, non-volatile DeclRefExpr inside an ICE
   is of integral or enumeration type (a reference isn't OK!)
 - In C++11, DeclRefExprs for objects of const literal type initialized with
   value-dependent expressions are themselves value-dependent.
 - So are references initialized with value-dependent expressions (though this
   case is missing from the C++11 standard, along with many others).

llvm-svn: 144056
2011-11-08 01:31:09 +00:00
Richard Smith f3e9e43da4 Constant expression evaluation: support for arrays.
llvm-svn: 143922
2011-11-07 09:22:26 +00:00
Richard Smith 8081560048 Constant expression evaluation: preserve subobject designator when flattening a
core constant value down to an APValue.

llvm-svn: 143909
2011-11-07 05:07:52 +00:00
Richard Smith a08acd8588 Allow constexpr variables' initializers to be folded in C++11 mode. This
partially undoes the revert in r143491, but does not introduce any new instances
of the underlying issue (which is not yet fixed) in code which does not use
the 'constexpr' keyword.

llvm-svn: 143905
2011-11-07 03:22:51 +00:00
Richard Smith fe5354b945 Clean up C++11 constant expression testing.
llvm-svn: 143720
2011-11-04 18:32:57 +00:00
Richard Smith 96e0c101fe Constant expression evaluation: track the manner in which an lvalue was written,
to allow us to implement the C++11 rule that a non-active union member can't be
read, and use it to implement subobject access for string literals.

llvm-svn: 143677
2011-11-04 02:25:55 +00:00
Douglas Gregor dd847baadd When we're checking a friend function template in an out-of-line class
definition, we may not have a scope corresponding to the namespace
where that friend function template actually lives. Work around this
issue by faking up a scope with the appropriate DeclContext.

This is a bit of a hack, but it fixes <rdar://problem/10204947>.

llvm-svn: 143614
2011-11-03 16:37:14 +00:00
Douglas Gregor 10f939c3db Don't build member initializers for zero-length or incomplete arrays,
and don't try to destroy them, either. Fixes
<rdar://problem/10228639>.

llvm-svn: 143584
2011-11-02 23:04:16 +00:00
Douglas Gregor c3ae7c363e When we run into a constructor or destructor that is defined in the
wrong class, make sure to drop it immediately; we don't want that
constructor to be available within the DeclContext. Fixes
<rdar://problem/9677163>.

llvm-svn: 143506
2011-11-01 22:13:30 +00:00
Richard Smith 1a77e8d10d Fix r143463 to test what it was intended to test.
llvm-svn: 143505
2011-11-01 21:48:46 +00:00
Richard Smith 1f1f2d8ca3 Temporarily disable lvalue-to-rvalue conversions on const pointers while an
apparent miscompile triggered by this is investigated. This is essentially a
revert of r143298.

llvm-svn: 143491
2011-11-01 20:38:59 +00:00
Richard Smith fec0992aca Implement C++11 'constexpr calls must return constant expressions' rule, and
perform the code simplifications this rule allows.

llvm-svn: 143463
2011-11-01 16:57:24 +00:00
Sebastian Redl 72ef7bc2b5 Enable function call and some overload resolution with parameters of aggregate class type and initializer list arguments.
llvm-svn: 143462
2011-11-01 15:53:09 +00:00
Eli Friedman c6be94b3de Don't try to fold comparisons between the address of an object and an arbitrary integer constant. Fixes regression from r143334.
llvm-svn: 143374
2011-10-31 22:28:05 +00:00
Eli Friedman 90a2cdf1fb Add missing lvalue-to-rvalue conversion.
llvm-svn: 143364
2011-10-31 20:59:03 +00:00
Richard Smith 4e4c78ffff C++11 generalized constant expression handling: evaluation support for
materialized temporaries.

llvm-svn: 143335
2011-10-31 05:52:43 +00:00
Richard Smith 83c682115b C++11 generalized constant expressions: evaluate equality comparisons between
arbitrary pointers, if those pointers don't point to weak objects or literals.

llvm-svn: 143334
2011-10-31 05:11:32 +00:00
Richard Smith 8b3497ee54 C++11 generalized constant expressions: support pointer comparisons where the
result is not unspecified.

llvm-svn: 143329
2011-10-31 01:37:14 +00:00
Richard Smith 35a1f85466 constexpr evaluation: allow lvalue-to-rvalue conversion on any literal type, not
just integers and floating point types. Since we don't support evaluating class
types or performing lvalue-to-rvalue conversions on array elements yet, this
just means pointer types right now.

llvm-svn: 143298
2011-10-29 21:53:17 +00:00
Richard Smith 0b0a0b6174 constexpr function substitution:
Track the function invocation where an lvalue referring to a constexpr function
parameter originated from, and use it to substitute the correct argument and to
determine whether such an argument's lifetime has ended.

llvm-svn: 143296
2011-10-29 20:57:55 +00:00