Commit Graph

1687 Commits

Author SHA1 Message Date
Douglas Gregor 21673c4e7e Scoped enumerations should not be treated as integer types (in the C
sense). Fixes <rdar://problem/9366066> by eliminating an inconsistency
between C++ overloading (which handled scoped enumerations correctly)
and C binary operator type-checking (which didn't).

llvm-svn: 130924
2011-05-05 16:13:52 +00:00
Douglas Gregor 1d33f8d8a0 With invalid overloaded operators, we can get into funny cases where
the overloading of member and non-member functions results in arity
mismatches that don't fit well into our overload-printing scheme. This
only happens for invalid code (which breaks the arity invariants for
these cases), so just suppress the diagnostic rather than inventing
anything new. Fixes <rdar://problem/9222009>.

llvm-svn: 130902
2011-05-05 00:13:13 +00:00
Matt Beaumont-Gay 3c27391a90 Implement Sema::isExprCallable.
We can use this to produce nice diagnostics (and try to fixit-and-recover) in
various cases where we might see "MyFunction" instead of "MyFunction()". The
changes in SemaExpr are an example of how to use isExprCallable.

llvm-svn: 130878
2011-05-04 22:10:40 +00:00
Alexis Hunt 6118d6642b Implement a better version of delegating constructor cycle detection.
This is more efficient as it's all done at once at the end of the TU.
This could still get expensive, so a flag is provided to disable it. As
an added bonus, the diagnostics will now print out a cycle.

The PCH test is XFAILed because we currently can't deal with a note
emitted in the header and I, being tired, see no other way to verify the
serialization of delegating constructors. We should probably address
this problem /somehow/ but no good solution comes to mind.

llvm-svn: 130836
2011-05-04 05:57:24 +00:00
Alexis Hunt 159bdaa50e Ensure that delegating constructor loop detection uses canonical
declarations.

llvm-svn: 130821
2011-05-04 01:19:04 +00:00
Douglas Gregor ed8a29b855 When tag lookup finds something ambiguous, and we're defining a new
tag, filter out those ambiguous names that we found if they aren't
within the declaration context where this newly-defined tag will be
visible.

This is basically a hack, because we really need to fix the lookup of
tag declarations in this case to not find things it
shouldn't. However, it's better than what we had before, and it fixes
<rdar://problem/9168556>. 

llvm-svn: 130810
2011-05-04 00:25:33 +00:00
Alexis Hunt 9d47faf686 Ensure that destructors are properly inovked when an exception leaves
the body of a delegating constructor call.

This means that the delegating constructor implementation should be
complete and correct, though there are some rough edges (diagnostic
quality with the cycle detection and using a deleted destructor).

llvm-svn: 130803
2011-05-03 23:05:34 +00:00
Douglas Gregor 3bb2a81539 Extend -Wnon-pod-memset to also encompass memcpy() and memmove(),
checking both the source and the destination operands, renaming the
warning group to -Wnon-pod-memaccess and tweaking the diagnostic text
in the process.

llvm-svn: 130786
2011-05-03 20:37:33 +00:00
Douglas Gregor a74926b518 Separate the -Wnon-pod-memset warnings into two separate warnings:
- a default-on warning for pointers to dynamic classes (= classes with vtables)
  - a default-off warning for other non-POD types

llvm-svn: 130781
2011-05-03 20:05:22 +00:00
Douglas Gregor 953beb4715 Only check the use of memset() if we're refering to a C function named
'memset' with external linkage.

llvm-svn: 130770
2011-05-03 18:11:37 +00:00
Argyrios Kyrtzidis 69a2c924b9 Add a warning for when reinterpret_cast leads to undefined behavior, patch by Richard Trieu!
llvm-svn: 130703
2011-05-02 18:21:19 +00:00
Alexis Hunt 61bc173784 Fully implement delegating constructors!
As far as I know, this implementation is complete but might be missing a
few optimizations. Exceptions and virtual bases are handled correctly.

Because I'm an optimist, the web page has appropriately been updated. If
I'm wrong, feel free to downgrade its support categories.

llvm-svn: 130642
2011-05-01 07:04:31 +00:00
Francois Pichet af538d9ee6 Add a triple to this test, otherwise it fails under MSVC because wchar_t is unsigned with the i686-pc-win32 triple.
llvm-svn: 130636
2011-05-01 04:32:34 +00:00
Eli Friedman 786d087ebd PR9792: Make sure to use the right definition of wchar_t when the default
wchar_t is an unsigned type.

llvm-svn: 130620
2011-04-30 19:24:24 +00:00
Chandler Carruth 61f4cbf38a Make type-traits reflect that Clang's vectors act like scalar types.
llvm-svn: 130606
2011-04-30 10:46:26 +00:00
Chandler Carruth 7623757cd0 Switch the type-trait like APIs on the AST to only check for incomplete
types after looking through arrays. Arrays with an unknown bound seem to
be specifically allowed in the library type traits in C++0x, and GCC's
builtin __is_trivial returns 'true' for the type 'int[]'. Now Clang
agrees with GCC about __is_trivial here.

Also hardens these methods against dependent types by just returning false.

llvm-svn: 130605
2011-04-30 10:31:50 +00:00
Chandler Carruth f9e7410468 Disable -Wnon-pod-memset for now while I try to reduce the false
positives still further.

The plan is to:

1) Create a more targeted warning for memset of memory pointing at
   a type with virtual methods or bases where a vptr would be
   overwritten.
2) Consider turning the above warning back on by default.
3) Evaluate whether any false positives in the existing warning can be
   detected and white listed in the warning implementation.
4) If #3 lowers the noise floor enough, enable the full warning in -Wall
   or -Wextra.

Comments or suggestions welcome. Even more welcome are specific test
cases which trigger the warning and shouldn't.

llvm-svn: 130538
2011-04-29 20:58:14 +00:00
Chandler Carruth c37485e6cb Relax the non-POD memset warning to use the less restrictive C++11
definition of POD. Specifically, this allows certain non-aggregate
types due to their data members being private.

The representation of C++11 POD testing is pretty gross. Any suggestions
for improvements there are welcome. Especially the name
'isCXX11PODType()' seems truly unfortunate.

llvm-svn: 130492
2011-04-29 09:46:08 +00:00
Douglas Gregor f8e894a103 Oops
llvm-svn: 130469
2011-04-29 01:50:40 +00:00
Douglas Gregor 63180b1190 libstdc++ 4.2 also uses __is_same as a struct name, which conflicts with our new type trait __is_same
llvm-svn: 130468
2011-04-29 01:38:03 +00:00
Douglas Gregor d517d55484 When determining whether two types are reference-compatible, check
non-CVR qualifiers as well as CVR qualifiers. For example, don't allow
a reference to an integer in address space 1 to bind to an integer in
address space 2.

llvm-svn: 130411
2011-04-28 17:56:11 +00:00
Douglas Gregor 068730992c libstdc++ 4.4 uses __is_signed as an identifier, while Clang treats it
as a keyword for the __is_signed type trait. Cope with this conflict
via some hackish recovery: if we see a declaration of the form

 static const bool __is_signed

then we stop treating __is_signed as a keyword and instead treat it as
an identifier. It's ugly, but it's better than making the __is_signed
type trait conditional on some language flag. Fixes PR9804.

llvm-svn: 130399
2011-04-28 15:48:45 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
John Wiegley 6242b6a688 Implementation of Embarcadero array type traits
Patch authored by John Wiegley.

These are array type traits used for parsing code that employs certain
features of the Embarcadero C++ compiler: __array_rank(T) and
__array_extent(T, Dim).

llvm-svn: 130351
2011-04-28 00:16:57 +00:00
John Wiegley 65497cce20 t/clang/type-traits
Patch authored by John Wiegley.

These type traits are used for parsing code that employs certain features of
the Embarcadero C++ compiler.  Several of these constructs are also desired by
libc++, according to its project pages (such as __is_standard_layout).

llvm-svn: 130342
2011-04-27 23:09:49 +00:00
Chandler Carruth ede9d33cde Heh, funny thing, 'void' isn't a POD type. Nice of us to suggest it to
silence this warning. ;]

Fixed that obvious bug and added a bit more testing as well.

llvm-svn: 130318
2011-04-27 18:48:59 +00:00
Chandler Carruth 53caa4d4fa Add a warning (-Wnon-pod-memset) for calls to memset() with
a destination pointer that points to a non-POD type. This can flag such
horrible bugs as overwriting vptrs when a previously POD structure is
suddenly given a virtual method, or creating objects that crash on
practically any use by zero-ing out a member when its changed from
a const char* to a std::string, etc.

llvm-svn: 130299
2011-04-27 07:05:31 +00:00
John McCall 5476666d17 Diagnose attempts to implicitly instantiate a template before it is
fully defined.  Somehow this escaped notice for a very long time.

llvm-svn: 130298
2011-04-27 06:46:31 +00:00
Chandler Carruth 938e4a89dd Add the test that I intended to submit with r130055, but forgot to add.
Apologies.

llvm-svn: 130291
2011-04-27 05:25:42 +00:00
Douglas Gregor 8b02cd0bea Extend Sema::ClassifyName() to support C++, ironing out a few issues
in the classification of template names and using declarations. We now
properly typo-correct the leading identifiers in statements to types,
templates, values, etc. As an added bonus, this reduces the number of
lookups required for disambiguation.

llvm-svn: 130288
2011-04-27 04:48:22 +00:00
John McCall 0009fcc39e Make yet another placeholder type, this one marking that an expression is a bound
member function, i.e. something of the form 'x.f' where 'f' is a non-static
member function.  Diagnose this in the general case.  Some of the new diagnostics
are probably worse than the old ones, but we now get this right much more
universally, and there's certainly room for improvement in the diagnostics.

llvm-svn: 130239
2011-04-26 20:42:42 +00:00
Argyrios Kyrtzidis bd0a3fe5e8 'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302, this time for C++ as well.
llvm-svn: 130157
2011-04-25 21:39:50 +00:00
Chris Lattner cdb591af03 fix PR9474, a crash with -fshort-enum and C++ templates: when instantiating
the enum decl, we need to use an integer type the same size as the enumerator,
which may not be the promoted type with packed enums.

llvm-svn: 130148
2011-04-25 20:37:58 +00:00
John Wiegley f9f6584e95 t/clang/expr-traits
Patch authored by David Abrahams.

These two expression traits (__is_lvalue_expr, __is_rvalue_expr) are used for
parsing code that employs certain features of the Embarcadero C++ compiler.

llvm-svn: 130122
2011-04-25 06:54:41 +00:00
Chandler Carruth e71d0628f7 Implement most of the remaining logic in __is_literal type trait. This
should now support all of the C++98 types, and all of the C++0x types
Clang supports.

llvm-svn: 130079
2011-04-24 02:49:34 +00:00
Chandler Carruth 65fa1fd18e Add support for '__is_literal_type' spelling of the existing
'__is_literal' type trait for GCC compatibility. At least one relased
version if libstdc++ uses this name for the trait despite it not being
documented anywhere.

llvm-svn: 130078
2011-04-24 02:49:28 +00:00
Chandler Carruth ad7d404732 Begin tracking trivialness of move constructors and move assignment
operators in C++ record declarations.

This patch starts off by updating a bunch of the standard citations to
refer to the draft 0x standard so that the semantics intended for move
varianst is clear. Where necessary these are duplicated so they'll be
available in doxygen.

It adds bit fields to keep track of the state for the move constructs,
and updates all the code necessary to track this state (I think) as
members are declared for a class. It also wires the state into the
various trait-like accessors in the AST's API, and tests that the type
trait expressions now behave correctly in the presence of move
constructors and move assignment operators.

This isn't complete yet due to these glaring FIXMEs:
1) No synthesis of implicit move constructors or assignment operators.
2) I don't think we correctly enforce the new logic for both copy and
   move trivial checks: that the *selected* copy/move
   constructor/operator is trivial. Currently this requires *all* of them
   to be trivial.
3) Some of the trait logic needs to be folded into the fine-grained
   trivial bits to more closely match the wording of the standard. For
   example, many of the places we currently set a bit to track POD-ness
   could be removed by querying other more fine grained traits on
   demand.

llvm-svn: 130076
2011-04-23 23:10:33 +00:00
Chandler Carruth 78ef0957d4 Flesh out these tests just a tad more. This provides targeted
'DerivesHasFoo' types for various non-POD constructs in the base class.
Only __is_pod and __is_trivial are wired up to these, not sure how much
more of this type of exhaustive testing is really interesting.

llvm-svn: 130075
2011-04-23 21:02:37 +00:00
Chandler Carruth 0850b9d4c9 Test POD and trivial type traits given a class derived from a generic
non-POD type.

It might be nicer to have a Derives* variant for each of HasCons,
HasCopy, etc. Then we could test each of those and also test the __has_*
traits. WIP.

llvm-svn: 130074
2011-04-23 20:51:42 +00:00
Chandler Carruth 7e5eaf1173 Use a more precise name for some of the types here, and re-group several
of the tests using those types to have a (hopefully) more logical
ordering now that doing so doesn't cause unreadable deltas of counters
changing.

llvm-svn: 130073
2011-04-23 20:51:39 +00:00
Chandler Carruth 21c6a044ec Mechanical change moving all of the test statements away from a pattern
that requires needless noise in every patch (due to numbers changing) or
poorly grouped test cases in order to have strictly increasing numbers.
This will make my subsequent patches much less ugly. =D

llvm-svn: 130072
2011-04-23 20:51:37 +00:00
Chandler Carruth a3e1f9a02c Implement basic __is_trivial type-trait support, enough to close PR9472.
This introduces a few APIs on the AST to bundle up the standard-based
logic so that programmatic clients have access to exactly the same
behavior.

There is only one serious FIXME here: checking for non-trivial move
constructors and move assignment operators. Those bits need to be added
to the declaration and accessors provided.

This implementation should be enough for the uses of __is_trivial in
libstdc++ 4.6's C++98 library implementation.

Ideas for more thorough test cases or any edge cases missing would be
appreciated. =D

llvm-svn: 130057
2011-04-23 10:47:28 +00:00
Chandler Carruth 153329dad7 GCC overloads -Wwrite-strings just to make it extra confusing. While it
changes language semantics in C and ObjC (which Clang has supported for
a while), in C++ it's the name used for Clang's
-Wdeprecated-writable-strings.

Clang's name is at least less overloaded if still confusing (the string
isn't writable, we just allow converting to a non-const pointer without
warning), so I've left it in place and made the GCC name an alias for
compatibility.

With this I've implemented all the aspects of GCC's -Wwrite-strings I've
encountered which didn't work with Clang.

llvm-svn: 130052
2011-04-23 06:54:44 +00:00
Argyrios Kyrtzidis bf04231a72 Don't allow reinterpret_cast to reference of vector element and property expression. Thanks goes to Eli Friedman!
llvm-svn: 130036
2011-04-22 23:57:57 +00:00
Argyrios Kyrtzidis 47a1285a69 reinterpret_cast to reference of a bit-field is not allowed.
Fixes rdar://9202628 & http://llvm.org/PR9564.

llvm-svn: 130024
2011-04-22 22:31:13 +00:00
Douglas Gregor 9750969178 At the end of the translation unit, defining a vtable can introduce
new templates that need to be instantiated and vice-versa. Iterate
until we've instantiated all required templates and defined all
required vtables. Fixed PR9325 / <rdar://problem/9055177>.

llvm-svn: 130023
2011-04-22 22:25:37 +00:00
Chandler Carruth 56773db7d4 I concur with DPG here. This does indeed apply in 0x mode. Added test
cases that demonstrates exactly why this does indeed apply in 0x mode.

If isPOD is currently broken in 0x mode, we should fix that directly
rather than papering over it here.

llvm-svn: 130007
2011-04-22 19:01:39 +00:00
Argyrios Kyrtzidis 8e4be0b1ea Don't enter a qualified scope for an invalid decl.
Fixes assertion later on. rdar://9122937 & http://llvm.org/PR9459

llvm-svn: 130006
2011-04-22 18:52:25 +00:00
Argyrios Kyrtzidis 7a6f2a358a In IsUserDefinedConversion try to recover from RequireCompleteType returning true.
Fixes an assertion later on, rdar://9122862 & http://llvm.org/PR9460.

llvm-svn: 130000
2011-04-22 17:45:37 +00:00
Francois Pichet e900b10a29 Downgrade error "static declaration of 'foo' follows non-static declaration" to a warning in Microsoft mode.
llvm-svn: 129985
2011-04-22 08:14:00 +00:00
Argyrios Kyrtzidis 98feafed27 Fix crashing rdar://9122854 & http://llvm.org/PR9461.
llvm-svn: 129967
2011-04-22 01:18:40 +00:00
Argyrios Kyrtzidis 1618023018 We regard a function as 'unused' from the codegen perspective, so our warnings diverge from
gcc's unused warnings which don't get emitted if the function is referenced even in an unevaluated context
(e.g. in templates, sizeof, etc.). Also, saying that a function is 'unused' because it won't get codegen'ed
is somewhat misleading.

- Don't emit 'unused' warnings for functions that are referenced in any part of the user's code.
- A warning that an internal function/variable won't get emitted is useful though, so introduce
  -Wunneeded-internal-declaration which will warn if a function/variable with internal linkage is not
  "needed" ('used' from the codegen perspective), e.g:

  static void foo() { }

  template <int>
  void bar() {
    foo();
  }

test.cpp:1:13: warning: function 'foo' is not needed and will not be emitted
static void foo() { }
            ^

Addresses rdar://8733476.

llvm-svn: 129794
2011-04-19 19:51:10 +00:00
Douglas Gregor 39d1a0973d Forbid the use of C++ new/delete to allocate/free objects within an
address space. I could see that this functionality would be useful,
but not in its current form (where the address space is ignored):
rather, we'd want to encode the address space into the parameter list
passed to operator new/operator delete somehow, which would require a
bunch more semantic analysis.

llvm-svn: 129593
2011-04-15 19:46:20 +00:00
Douglas Gregor b472e93af7 Implement appropriate semantics for C++ casting and conversion when
dealing with address-space- and GC-qualified pointers. Previously,
these qualifiers were being treated just like cvr-qualifiers (in some
cases) or were completely ignored, leading to uneven behavior. For
example, const_cast would allow conversion between pointers to
different address spaces.

The new semantics are fairly simple: reinterpret_cast can be used to
explicitly cast between pointers to different address spaces
(including adding/removing addresss spaces), while
static_cast/dynamic_cast/const_cast do not tolerate any changes in the
address space. C-style casts can add/remove/change address spaces
through the reinterpret_cast mechanism. Other non-CVR qualifiers
(e.g., Objective-C GC qualifiers) work similarly.

As part of this change, I tweaked the "casts away constness"
diagnostic to use the term "casts away qualifiers". The term
"constness" actually comes from the C++ standard, despite the fact
that removing "volatile" also falls under that category. In Clang, we
also have restrict, address spaces, ObjC GC attributes, etc., so the
more general "qualifiers" is clearer.

llvm-svn: 129583
2011-04-15 17:59:54 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
Fariborz Jahanian bc2ee9382c Match pointer of compatible vection types.
// rdar://9208404

llvm-svn: 129536
2011-04-14 20:33:36 +00:00
Anders Carlsson d162fb83f2 In C++, when initializing an array from a pascal string, it's OK if the array
is 1 element smaller than the string, because we can just strip off the last
null character. This matches GCC.

llvm-svn: 129490
2011-04-14 00:41:11 +00:00
Anders Carlsson a5a9bafeb9 Rename test.
llvm-svn: 129486
2011-04-13 23:55:47 +00:00
Chandler Carruth 0a7aa3b60b Teach -Wuninitialized about C++'s typeid expression, including both the
evaluated and unevaluated contexts. Add some testing of sizeof and
typeid.

Both of the typeid tests added here were triggering warnings previously.
Now the one false positive is suppressed without suppressing the warning
on actually buggy code.

llvm-svn: 129431
2011-04-13 08:18:42 +00:00
Francois Pichet 48c946e5ef In Microsoft mode, within class scope, if a CXXScopeSpec's type is equal to the type of one of the base classes then downgrade the missing typename error to a warning. Up to now this is the only case I found where MSVC doesn't require "typename" at class scope. Really strange!
This fixes 1 error when parsing the MSVC 2008 header files.
Example:

template<class T> class A {
public:
  typedef int TYPE;
};
template<class T> class B : public A<T> {
public:
  A<T>::TYPE a; // no typename required because A<T> is a base class.
};

llvm-svn: 129425
2011-04-13 02:38:49 +00:00
John McCall 2979fe01da After some discussion with Doug, we decided that it made a lot more sense
for __unknown_anytype resolution to destructively modify the AST.  So that's
what it does now, which significantly simplifies some of the implementation.
Normal member calls work pretty cleanly now, and I added support for
propagating unknown-ness through &.

llvm-svn: 129331
2011-04-12 00:42:48 +00:00
John McCall 2d2e870745 More __unknown_anytype work.
llvm-svn: 129269
2011-04-11 07:02:50 +00:00
Eli Friedman 554eba9c08 PR9669: implement correct checking for [dcl.init.string]p2.
llvm-svn: 129260
2011-04-11 00:23:45 +00:00
Chandler Carruth 016ef400c4 Enhance the diagnostic for literal float -> int conversions to suggest
rewriting the literal when the value is integral. It is not uncommon to
see code written as:

  const int kBigNumber = 42e5;

Without any real awareness that this is no longer an ICE. The note helps
automate and ease the process of fixing code that violates the warning.

llvm-svn: 129243
2011-04-10 08:36:24 +00:00
Francois Pichet 53fe2bb29e MSVC accepts that default parameters be redefined for member functions
of template class. The new value is ignored.

This fixes 1 error when parsing MSVC 2010 header files with clang.

llvm-svn: 129240
2011-04-10 03:03:52 +00:00
John McCall 39439739cf Fix a bunch of major problems with __unknown_anytype and properly test
for them.  The only major missing feature is references.

llvm-svn: 129234
2011-04-09 22:50:59 +00:00
Chandler Carruth 66a7b04767 Clean up the bool conversion warning. Group it with other conversion
warnings, and make its text appropriate for constant bool expressions
other than 'false'. This should finish off PR9612.

llvm-svn: 129205
2011-04-09 07:48:17 +00:00
Chandler Carruth ffab873ed5 Add support for warning on general null pointer expressions of boolean
type rather than just the literal 'false'. This begins fixing PR9612,
but the message is now wrong. WIP, the cleanup of the messaging is next.

llvm-svn: 129204
2011-04-09 07:32:05 +00:00
Chandler Carruth 42983aef34 Switch 'is possibly uninitialized' to 'may be uninitialized' based on
Chris's feedback.

llvm-svn: 129127
2011-04-08 06:47:15 +00:00
Chandler Carruth 278f89732f Now that the analyzer is distinguishing between uninitialized uses that
definitely have a path leading to them, and possibly have a path leading
to them; reflect that distinction in the warning text emitted.

llvm-svn: 129126
2011-04-08 06:33:38 +00:00
Ted Kremenek 97c393807b Teach -Wuninitialized to not warn about variables declared in C++ catch statements.
llvm-svn: 129102
2011-04-07 20:02:56 +00:00
John McCall 319963434c Basic, untested implementation for an "unknown any" type requested by LLDB.
The idea is that you can create a VarDecl with an unknown type, or a
FunctionDecl with an unknown return type, and it will still be valid to
access that object as long as you explicitly cast it at every use.  I'm
still going back and forth about how I want to test this effectively, but
I wanted to go ahead and provide a skeletal implementation for the LLDB
folks' benefit and because it also improves some diagnostic goodness for
placeholder expressions.

llvm-svn: 129065
2011-04-07 08:22:57 +00:00
Anders Carlsson 6b06e18c70 Wide Pascal strings should be of type wchar_t[] and not unsigned char[].
llvm-svn: 129017
2011-04-06 18:42:48 +00:00
Chandler Carruth b5d4831f83 Fix PR9624 by explicitly disabling uninitialized warnings for direct self-init:
int x = x;

GCC disables its warnings on this construct as a way of indicating that
the programmer intentionally wants the variable to be uninitialized.
Only the warning on the initializer is turned off in this iteration.

This makes the code a lot more ugly, but starts commenting the
surprising behavior here. This is a WIP, I want to refactor it
substantially for clarity, and to determine whether subsequent warnings
should be suppressed or not.

llvm-svn: 128894
2011-04-05 17:41:31 +00:00
Ted Kremenek 378819342e Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with numerous CFG and UninitializedValues analysis changes:
1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt.
2) Update ExprEngine (the static analyzer) to understand (1), so not to regress.
3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method.
4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases.

The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer
contained control-flow.

llvm-svn: 128858
2011-04-04 23:29:12 +00:00
Ted Kremenek 352a7081a8 -Wuninitialized: don't warn about uninitialized variables in unreachable code.
llvm-svn: 128840
2011-04-04 20:30:58 +00:00
Eli Friedman 72adff255e PR9585: add __decltype as a keyword. While I'm here, alphabetize the list.
llvm-svn: 128809
2011-04-04 07:19:40 +00:00
Eli Friedman 2d9c47ea6c PR9615: make sure we destroy any temporaries returned by operator->.
I'm pretty sure this is the right fix, but I would appreciate it if someone
else would double-check.

llvm-svn: 128806
2011-04-04 01:18:25 +00:00
Nico Weber cc2b8717c5 Make -Wheader-hygiene not complain about USING_NAMESPACE_THROUGH_MACRO in a non-header file.
llvm-svn: 128780
2011-04-02 19:45:15 +00:00
Francois Pichet 117d23c5bc Add a triple to make the test friendly on no windows platform.
llvm-svn: 128459
2011-03-29 11:38:04 +00:00
Francois Pichet 3096d209bf Accept __declspec(dllimport) for function defined at class scope in Microsoft mode.
This fixes a bunch of errors when compiling MSVC header files with the -DDLL flag.

llvm-svn: 128457
2011-03-29 10:39:17 +00:00
Ted Kremenek 03325c4be9 Add workaround for Sema issue found in <rdar://problem/9188004>, which leads to an assertion failure in the uninitialized variables analysis. The problem is that Sema isn't properly registering a variable in a DeclContext (which -Wuninitialized relies on), but
my expertise on the template instantiation logic isn't good enough to fix this problem for real.  This patch worksaround the
problem in -Wuninitialized, but we should fix it for real later.

llvm-svn: 128443
2011-03-29 01:40:00 +00:00
Argyrios Kyrtzidis ba699d611b Don't do the checks of Sema::DiagnoseEqualityWithExtraParens() on type-dependent expressions. Fixes rdar://9027658.
llvm-svn: 128437
2011-03-28 23:52:04 +00:00
Matt Beaumont-Gay 93615d9912 Fix PR9572 and neighboring lurking crashers.
llvm-svn: 128401
2011-03-28 01:39:13 +00:00
Chandler Carruth edcc04e05b Add tests for the uninitialized checks added in r128376. Also clean up
and flesh out the existing uninitialized testing for field initializers.

The tests come from Richard's original patch, but I've cleaned them up
a bit and ordered them more naturally.

Also, I added a test for the most simple base case:
int x = x;

And it turns out we miss this one! =[ That and another bad FIXME on the
field initializer checking are left in the test.

llvm-svn: 128394
2011-03-27 20:35:59 +00:00
Douglas Gregor a172e08824 Improve -Wheader-hygiene to warn about using directives inside linkage
specifications within the global scope, from Elliot Glaysher.

llvm-svn: 128352
2011-03-26 22:25:30 +00:00
John McCall 4d55f5a893 Don't warn about the 'extern' in 'extern "C"' on a tag decl. This is
usually useless, but not always.

llvm-svn: 128326
2011-03-26 02:09:52 +00:00
Nick Lewycky d469321186 Apply the nonnull attribute to constructor expressions too.
llvm-svn: 128253
2011-03-25 01:44:32 +00:00
Douglas Gregor d7d7e0d3df Minor fix in the injection of labels, since we want to look at the redeclaration context of each declaration in the identifier chain. Should fix Linux self-host
llvm-svn: 128210
2011-03-24 14:35:16 +00:00
Douglas Gregor 33f352ca62 Fix the insertion of label declarations into the identifier chain in
the case where we only have a single identifier with that name in the
chain. Fixes PR9463 for real this time.

llvm-svn: 128208
2011-03-24 10:35:39 +00:00
Anders Carlsson 98766db785 Add a new warning for exit-time destructors.
llvm-svn: 128188
2011-03-24 01:01:41 +00:00
Douglas Gregor 336a15e041 Unbreak test
llvm-svn: 128168
2011-03-23 21:19:43 +00:00
Marshall Clow e7deac8cdc Add a test for !ptr-to-member (should fail)
llvm-svn: 128158
2011-03-23 19:44:36 +00:00
Douglas Gregor 20b2ebd785 Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,

  void foo()
  __attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));

says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:

  - If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
    will result in a deprecation warning, as if we had placed
    attribute((deprecated)) on it (but with a better diagnostic)
  - If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
    will result in an "unavailable" warning (in C)/error (in C++), as
    if we had placed attribute((unavailable)) on it
  - If we choose a deployment target prior to 10.2, foo() is
    weak-imported (if it is a kind of entity that can be weak
    imported), as if we had placed the weak_import attribute on it.

Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.

The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.

Addresses <rdar://problem/6690412>.

As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.

llvm-svn: 128127
2011-03-23 00:50:03 +00:00
John McCall 30cd20a316 Apply Jonathan Sauer's proposed solution to PR9519. Thanks!
llvm-svn: 128075
2011-03-22 07:16:37 +00:00
Peter Collingbourne a85fc0a2f3 Only objects are declared const by a constexpr specifier, per C++0x [dcl.constexpr]p9
llvm-svn: 127967
2011-03-20 08:06:45 +00:00
Francois Pichet 13b4e68642 Downgrade err_mismatched_exception_spec to a ExtWarning in Microsoft mode. MSVC doesn't do any validation on exception specifications.
This remove 1 error when parsing MSVC stl lib with clang.

llvm-svn: 127961
2011-03-19 23:05:18 +00:00
Anton Yartsev acb43dbf9b makes vec_step operator work when AltiVec support is enabled
llvm-svn: 127949
2011-03-19 07:53:43 +00:00
Douglas Gregor 96a4bddefb Add an opt-in -Wheader-hygiene, which current diagnoses the use of
global using directives in C++ headers, from Elliot Glaysher!

llvm-svn: 127881
2011-03-18 16:10:52 +00:00
Richard Smith 9647d3ca02 Fix PR9488: 'auto' type substitution can fail (for instance, if it creates a reference-to-void type). Don't crash if it does.
Also fix an issue where type source information for the resulting type was being lost.

llvm-svn: 127811
2011-03-17 16:11:59 +00:00
Ted Kremenek 65ccd1d9b0 Fix test to test the right thing.
llvm-svn: 127803
2011-03-17 05:34:58 +00:00
Ted Kremenek 2551fbe928 Don't construct two CFGs just to run -Wuninitialized. While this causes new warnings to be flagged under -Wconditional-uninitialized, this is something we
can improve over time.

llvm-svn: 127802
2011-03-17 05:29:57 +00:00
Abramo Bagnara 9875a3ce70 Use ElaboratedType also for C.
llvm-svn: 127755
2011-03-16 20:16:18 +00:00
Douglas Gregor 89f3cd5c15 Clean up our handling of template-ids that resolve down to a single
overload, so that we actually do the resolution for full expressions
and emit more consistent, useful diagnostics. Also fixes an IRGen
crasher, where Sema wouldn't diagnose a resolvable bound member
function template-id used in a full-expression (<rdar://problem/9108698>).

llvm-svn: 127747
2011-03-16 19:16:25 +00:00
Douglas Gregor ce0bc31469 Don't indescriminately print overload candidates when we have invalid
operands to a binary expression; it doesn't make sense in all
contexts. The right answer would be to see if the user forgot at ().

Fixes <rdar://problem/9136502>.

llvm-svn: 127740
2011-03-16 18:21:05 +00:00
Douglas Gregor 6341ceedc5 Allow function calls to dereferenced member pointers of
pointer-to-function type. Fixes <rdar://problem/9065289>.

llvm-svn: 127739
2011-03-16 17:42:23 +00:00
Douglas Gregor a0ff0c34a7 Make sure that we always pop a function's scope *before* we call
ActOnFinishFunctionBody/ActOnBlockStmtExpr. This way, we ensure that
we diagnose undefined labels before the jump-scope checker gets run,
since the jump-scope checker requires (as its invariant) that all of
the GotoStmts be wired up correctly.

Fixes PR9495.

llvm-svn: 127738
2011-03-16 17:05:57 +00:00
Douglas Gregor 46c04e74fb When we're inserting a synthesized label declaration for a
forward-looking "goto" statement, make sure to insert it *after* the
last declaration in the identifier resolver's declaration chain that
is either outside of the function/block/method's scope or that is
declared in that function/block/method's specific scope. Previously,
we could end up inserting the label ahead of declarations in inner
scopes, confusing C++ name lookup.

Fixes PR9491/<rdar://problem/9140426> and <rdar://problem/9135994>.

Note that the crash-on-invalid PR9495 is *not* fixed. That's a
separate issue.

llvm-svn: 127737
2011-03-16 16:39:03 +00:00
Ted Kremenek 35c70f64db Teach CFGBuilder that the 'default' branch of a switch statement is dead if all enum values in a switch conditioned are handled.
llvm-svn: 127727
2011-03-16 04:32:01 +00:00
Ted Kremenek ea6c20adaf Take 2: merge -Wuninitialized-experimental into -Wuninitialized. Only *must-be-uninitialized* warnings are reported, with *maybe-uninitialized* under a separate flag. I await any fallout/comments/feedback, although hopefully this will produce no noise for users.
llvm-svn: 127670
2011-03-15 05:22:33 +00:00
Douglas Gregor 88764cf822 When synthesizing a label declaration based on a goto statement that
cannot yet be resolved, be sure to push the new label declaration into
the right place within the identifier chain. Otherwise, name lookup in
C++ gets confused when searching for names that are lexically closer
than the label. Fixes PR9463.

llvm-svn: 127623
2011-03-14 21:19:51 +00:00
Douglas Gregor e981bb0e5c -fwritable-strings should silence warnings about the deprecated string
-literal to char* conversion. Make it so.

llvm-svn: 127586
2011-03-14 16:13:32 +00:00
Sebastian Redl fa453cfdc3 Propagate the new exception information to FunctionProtoType.
Change the interface to expose the new information and deal with the enormous fallout.
Introduce the new ExceptionSpecificationType value EST_DynamicNone to more easily deal with empty throw specifications.
Update the tests for noexcept and fix the various bugs uncovered, such as lack of tentative parsing support.

llvm-svn: 127537
2011-03-12 11:50:43 +00:00
Douglas Gregor e9e27d95db Implement a hack intended to allow Clang to parse libstdc++ 4.5's
headers, which use C++0x generalized initializer lists. Per PR7069, it
appears that the only use is as the return type of a function, so this
commit enables this extension just in that narrow case. If it's enough
for libstdc++ 4.5, or if it can be trivially extended to work with
libstdc++ 4.5, we'll keep it. Otherwise, or if this breaks anything,
we'll revert and wait for the real feature.

llvm-svn: 127507
2011-03-11 23:10:44 +00:00
Rafael Espindola 6b7e3bc992 Fix PR9453 by not trying to print a warning about ignored qualifiers
in conversion functions.

llvm-svn: 127460
2011-03-11 04:56:58 +00:00
Ted Kremenek 897947434e Fix null dereference in CFGBlock::FilterEdge that was reported in PR 9412.
llvm-svn: 127176
2011-03-07 22:04:39 +00:00
Argyrios Kyrtzidis 7e25a95600 g++ is more permissive regarding flexible arrays.
It will accept flexible array in union and also as the sole element of a struct/class.

Fixes rdar://9065507.

llvm-svn: 127171
2011-03-07 20:04:04 +00:00
Douglas Gregor d99609ae48 When performing template argument deduction for a non-reference
conversion function when we're binding the result to a reference, drop
cv-qualifiers on the type we're referring to, since we should be
deducing a type that can be adjusted (via cv-qualification) to the
requested type. Fixes PR9336, and the remaining Boost.Assign failure.

llvm-svn: 127117
2011-03-06 09:03:20 +00:00
Matt Beaumont-Gay f8bb45f14d Much to my surprise, OverloadExprs can also point to function template decls.
llvm-svn: 127061
2011-03-05 02:42:30 +00:00
Douglas Gregor 93ded32026 Diagnose destructor templates. Fixes PR7904.
llvm-svn: 127042
2011-03-04 22:45:55 +00:00
Douglas Gregor 4cf85a725a When clearing a LookupResult structure, clear out the naming class,
too. Fixes PR7900.

While I'm in this area, improve the diagnostic when the type being
destroyed doesn't match either of the types we found.

llvm-svn: 127041
2011-03-04 22:32:08 +00:00
Ted Kremenek be52871b1a Correctly handle nested switch statements in CFGBuilder when on switch statement has a condition that evaluates to a constant.
llvm-svn: 126977
2011-03-04 01:03:41 +00:00
Argyrios Kyrtzidis 7a1778eba1 -Woverloaded-virtual shouldn't warn for static functions. Fixes rdar://9083431 & http://llvm.org/PR9396.
llvm-svn: 126966
2011-03-03 22:58:57 +00:00
Argyrios Kyrtzidis e02831423a Don't emit unused warning for deleted functions. Fixes rdar://8365684 & http://llvm.org/PR9391.
llvm-svn: 126950
2011-03-03 17:47:42 +00:00
Ted Kremenek 916c8357db Add coverage test for CFGImplicitDtor::getDestructorDecl() when handling typedefs.
llvm-svn: 126947
2011-03-03 17:07:11 +00:00
Douglas Gregor e29139c77d Eliminate redundant nested-name-specifiers on
TemplateSpecializationTypes, which also fixes PR9388.

llvm-svn: 126946
2011-03-03 17:04:51 +00:00
Ted Kremenek 8cfe207861 Teach CFGImplicitDtor::getDestructorDecl() about arrays of objects with destructors.
llvm-svn: 126910
2011-03-03 01:21:32 +00:00
Ted Kremenek 1676a042e3 Teach CFGImplicitDtor::getDestructorDecl() about reference types.
llvm-svn: 126909
2011-03-03 01:01:03 +00:00
Ted Kremenek e06a55c6b9 Introduce CFGImplicitDtor::isNoReturn() to query whether a destructor actually returns. Use this for -Wreturn-type to prune false positives reported in PR 6884.
llvm-svn: 126875
2011-03-02 20:32:29 +00:00
Douglas Gregor 9d80212115 Push nested-name-specifier source location information into template
template arguments. I believe that this is the last place in the AST
where we were storing a source range for a nested-name-specifier
rather than a proper nested-name-specifier location structure. (Yay!)

There is still a lot of cleanup to do in the TreeTransform, which
doesn't take advantage of nested-name-specifiers with source-location
information everywhere it could.

llvm-svn: 126844
2011-03-02 17:09:35 +00:00
John McCall 80ee5963fd Pretty up the wrong-number-of-arguments-for-attribute diagnostic by
using a custom plural form.  Split out the range diagnostics as their
own message.

llvm-svn: 126840
2011-03-02 12:15:05 +00:00
John McCall 8feeb49662 Semantic checking for exception specifications should be triggered by
whether C++ exceptions are enabled, not exceptions in general.  PR9358.

llvm-svn: 126820
2011-03-02 02:04:40 +00:00
Douglas Gregor e7c2065379 Push nested-name-specifier source-location information into dependent
template specialization types. This also required some parser tweaks,
since we were losing track of the nested-name-specifier's source
location information in several places in the parser. Other notable
changes this required:

  - Sema::ActOnTagTemplateIdType now type-checks and forms the
    appropriate type nodes (+ source-location information) for an
    elaborated-type-specifier ending in a template-id. Previously, we
    used a combination of ActOnTemplateIdType and
    ActOnTagTemplateIdType that resulted in an ElaboratedType wrapped
    around a DependentTemplateSpecializationType, which duplicated the
    keyword ("class", "struct", etc.) and nested-name-specifier
    storage.

  - Sema::ActOnTemplateIdType now gets a nested-name-specifier, which
    it places into the returned type-source location information.

  - Sema::ActOnDependentTag now creates types with source-location
    information.

llvm-svn: 126808
2011-03-02 00:47:37 +00:00
Ted Kremenek eff9a7ff91 Teach CFGBuilder to prune trivially unreachable case statements.
llvm-svn: 126797
2011-03-01 23:12:55 +00:00
Douglas Gregor a7a795bed1 Push nested-name-specifier source-location information into dependent
template specialization types. There are still a few rough edges to
clean up with some of the parser actions dropping
nested-name-specifiers too early.

llvm-svn: 126776
2011-03-01 20:11:18 +00:00
Ted Kremenek df26df726e For C++, enhance -Warray-bounds to recursively analyze array subscript accesses in ?: expressions.
llvm-svn: 126766
2011-03-01 18:41:00 +00:00
Douglas Gregor 48e6bbffa1 Implement comparison of C++0x scoped enumeration types. Fixes PR9333.
llvm-svn: 126752
2011-03-01 17:16:20 +00:00
Douglas Gregor 9760a666d6 When digging into a cv-qualified return type that is a pointer type to
diagnose ignored qualifiers on return types, only assume that there is
a pointer chunk if the type is *structurally* a pointer type, not if
it's a typedef of a pointer type. Fixes PR9328/<rdar://problem/9055428>.

llvm-svn: 126751
2011-03-01 17:04:42 +00:00
Chandler Carruth 477a999788 Move the bool-conversions behind the DiagRuntimeBehavior logic. It's
possible for these to show up due to metaprogramming both in unevaluated
contexts and compile-time dead branches.

Those aren't the bugs we're looking for.

llvm-svn: 126739
2011-03-01 03:29:37 +00:00
Douglas Gregor 3d0da5f5dd Push nested-name-specifier source location information into
DependentNameTypeLoc. Teach the recursive AST visitor and libclang how to
walk DependentNameTypeLoc nodes.

Also, teach libclang about TypedefDecl source ranges, so that we get
those. The massive churn in test/Index/recursive-cxx-member-calls.cpp
is a good thing: we're annotating a lot more of this test correctly
now.

llvm-svn: 126729
2011-03-01 01:34:45 +00:00
Douglas Gregor e16af53619 Push nested-name-specifier source location information into
CXXDependentScopeMemberExpr, and clean up instantiation of
nested-name-specifiers with dependent template specialization types in
the process.

llvm-svn: 126663
2011-02-28 18:50:33 +00:00
Anders Carlsson 6774b1f1c1 Add -fcxx-exceptions to all tests that use C++ exceptions.
llvm-svn: 126599
2011-02-28 00:40:07 +00:00
Fariborz Jahanian e6b127d7da Sprinkle optional text of the "unavailable' attribute
where ever such attribute causes an error diagnostic.

llvm-svn: 126509
2011-02-25 20:51:14 +00:00
Douglas Gregor 3a43fd645d Push nested-name-specifier source location information into
DependentScopeDeclRefExpr. Plus, give NestedNameSpecifierLoc == and !=
operators, since we're going to need 'em elsewhere.

llvm-svn: 126508
2011-02-25 20:49:16 +00:00
Matt Beaumont-Gay f4aec20e97 s/clang-cc1/clang_cc1
llvm-svn: 126501
2011-02-25 19:09:01 +00:00
Fariborz Jahanian bff158dc67 Print optional message for attr(unavailable) in C++ mode.
// rdar://9046492

llvm-svn: 126499
2011-02-25 18:38:59 +00:00
Douglas Gregor a6ce608b97 Push nested-name-specifier source-location information into
pseudo-destructor expressions. Also, clean up some
template-instantiation and type-checking issues with
pseudo-destructors.

llvm-svn: 126498
2011-02-25 18:19:59 +00:00
Douglas Gregor 0499ab6c35 Maintain nested-name-specifier source-location information through
instantiation of using declarations (all three forms).

llvm-svn: 126485
2011-02-25 15:54:31 +00:00
Chandler Carruth a28097da4f Rough fix for PR9323 that prevents Clang from marking copy constructor
declarations as referenced when in fact we're not going to even form
a call in the AST. This is significant because we attempt to allow as an
extension classes with intentionally private and undefined copy
constructors to have temporaries bound to references, and so shouldn't
warn about the lack of definition for that copy constructor when the
class is internal.

Doug, John wasn't really satisfied with the presence of overloading at
all. This is a stop-gap and there may be a better solution. If you can
give me some hints for how you'd prefer to see this solved, I'll happily
switch things over.

llvm-svn: 126480
2011-02-25 08:52:25 +00:00
Chandler Carruth 4322a2864e Fix the rest of PR9316 along with some other bugs spotted by inspection.
I tried to add test cases for these, but I can't because variables
aren't warned on the way functions are and the codegen layer appears to
use different logic for determining that 'a' and 'g' in the test case
should receive C mangling. I've included the test so that if we ever
switch the codegen layer to use these functions, we won't regress due to
latent bugs.

llvm-svn: 126453
2011-02-25 00:05:02 +00:00
Chandler Carruth 9682a2fd3a Likely fix for PR9316 and other unknown bugs: don't use the anonynmous
namespace blanket rule for variables and functions declared 'extern
"C"'.

llvm-svn: 126400
2011-02-24 19:03:39 +00:00
Chandler Carruth e721185799 Simplify messages as requested by Chris.
llvm-svn: 126389
2011-02-24 17:13:15 +00:00
Chris Lattner abcf38a064 compute the integer width, not the memory width here. We want to know that
_Bool is 1 bit, not 8.  This fixes an assertion on the testcase, which is
PR9304 and rdar://9045501.

llvm-svn: 126368
2011-02-24 07:31:28 +00:00
Douglas Gregor d7295bad84 Test case for previous commit
llvm-svn: 126360
2011-02-24 02:37:39 +00:00
Chandler Carruth 60ed89dc54 Handle value dependent LHS as well as RHS. Test both of these, they
don't seem to have been covered by our tests previously.

This should fix bootstrap failure.

llvm-svn: 126345
2011-02-24 00:03:53 +00:00
Ted Kremenek e4b316c15c Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.
llvm-svn: 126341
2011-02-23 23:06:04 +00:00
Chandler Carruth e71b378dc7 Fix the behavior of -Wignored-qualifiers on return type qualifiers in
several ways. We now warn for more of the return types, and correctly
locate the ignored ones. Also adds fix-it hints to remove the ignored
qualifiers. Fixes much of PR9058, although not all of it.

Patch by Hans Wennborg, a couple of minor style tweaks from me.

llvm-svn: 126321
2011-02-23 18:51:59 +00:00
Ted Kremenek 477c8f5440 Add test case for PR 9284, a false positive for -Warray-bounds that is now addressed using basic reachability analysis.
llvm-svn: 126291
2011-02-23 01:52:07 +00:00
Ted Kremenek 3427fac7c8 Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the related code is reachable. This suppresses some
diagnostics that occur in unreachable code (e.g., -Warray-bound).

We only pay the cost of doing the reachability analysis when we issue one of these diagnostics.

llvm-svn: 126290
2011-02-23 01:52:04 +00:00
Richard Smith 2abf6767e3 Fix PR9276: We were missing the checks for auto deducing to different types in the same declaration group in the template instantiation case.
llvm-svn: 126279
2011-02-23 00:37:57 +00:00
Matt Beaumont-Gay 06de2553f3 Clean up the error recovery at the bottom of Sema::LookupMemberExpr. This
mostly just shuffles various possibilities for recovery into a more
straightforward order, but also unifies a couple of diagnostics.

llvm-svn: 126266
2011-02-22 23:52:53 +00:00
Douglas Gregor 385d3fd97d When checking for abstract types, don't crash when we have a
FunctionProtoTypeLoc with NULL function parameter types, which can
occur in invalid code. Fixes PR9247 / <rdar://problem/9037911>.

llvm-svn: 126262
2011-02-22 23:21:06 +00:00
Fariborz Jahanian bb6db56028 Provide Fixit warning when 'auto' is intended as storage
specifier in legacy code. Patch is reviewed offline by Doug.
// rdar://9036633.

llvm-svn: 126261
2011-02-22 23:17:49 +00:00
Douglas Gregor 996a735b88 We need a longer long when testing this pathe Microsoft fixed-underlying-type extension for enumeration types
llvm-svn: 126250
2011-02-22 21:42:31 +00:00
Douglas Gregor a1aec29a2d Enable enumeration types with a fixed underlying type, e.g.,
enum X : long { Value = 0x100000000 };

when in Microsoft-extension mode (-fms-extensions). This (now C++0x)
feature has been supported since Microsoft Visual Studio .NET 2003.

llvm-svn: 126243
2011-02-22 20:32:04 +00:00
Douglas Gregor 6cd5ae4dfa Fix a little bug in the handling of enumeration types with a fixed
underlying type: we weren't parsing unnamed enumeration types with a
fixed underlying type.

llvm-svn: 126184
2011-02-22 02:55:24 +00:00
John McCall 15dd404c46 Don't warn about static const integral data members with in-line constant
initializers just because they don't have a proper out-of-line definition.
Such code is technically ill-formed but is too common and too unlikely to be
a problem to be seriously worth worrying about.

llvm-svn: 126137
2011-02-21 19:25:48 +00:00
Chandler Carruth d05b352b0e Clean up the tests for warning about unused function results given the
appropriate attribute. Add a bit more testing that finds a pretty bad
regression (since ~forever) in this warning. Fix it with a nice 2 line
change. =]

llvm-svn: 126098
2011-02-21 00:56:56 +00:00
Richard Smith 30482bc786 Implement the C++0x deduced 'auto' feature.
This fixes PR 8738, 9060 and 9132.

llvm-svn: 126069
2011-02-20 03:19:35 +00:00
Douglas Gregor 5b05454f24 Don't produce "comparison is always (true|false)" warnings when the
comparison itself is a constant expression. Fixes PR7536.

llvm-svn: 126057
2011-02-19 22:34:59 +00:00
Douglas Gregor b491ed36b4 Handle the resolution of a reference to a function template (which
includes explicitly-specified template arguments) to a function
template specialization in cases where no deduction is performed or
deduction fails. Patch by Faisal Vali, fixes PR7505!

llvm-svn: 126048
2011-02-19 21:32:49 +00:00
Anders Carlsson 68b36aff46 Disallow try/catch/throw when exceptions are disabled.
llvm-svn: 126039
2011-02-19 19:26:44 +00:00
Anders Carlsson 479d6f51e3 Pass -fexceptions to all tests that use try/catch/throw.
llvm-svn: 126037
2011-02-19 19:23:03 +00:00
Douglas Gregor 0cf82f6ad0 Teach the virtual-functions-without-virtual-destructor warning to only
warn about polymorphic classes (which have virtual functions) rather
than dynamic classes (which are polymorphic or have virtual bases).

llvm-svn: 126036
2011-02-19 19:14:36 +00:00
John McCall 8377967543 Warn about code that uses variables and functions with internal linkage
without defining them.  This should be an error, but I'm paranoid about
"uses" that end up not actually requiring a definition.  I'll revisit later.

Also, teach IR generation to not set internal linkage on variable
declarations, just for safety's sake.  Doing so produces an invalid module
if the variable is not ultimately defined.

Also, fix several places in the test suite where we were using internal
functions without definitions.

llvm-svn: 126016
2011-02-19 02:53:41 +00:00
Chandler Carruth 9c9127eace Fix a missed case in the NULL operand to conditional operator
diagnostics.

Patch by Stephen Hines.

llvm-svn: 125998
2011-02-19 00:13:59 +00:00
Chandler Carruth fc1ad1f371 Update the test error messages to match the update I made to the actual
messages.

llvm-svn: 125997
2011-02-19 00:12:23 +00:00
Chandler Carruth 98e3c568bf Fix PR8767, improve diagnostic wording when allocating an object of an
abstract class type.

Patch by Stephen Hines, with a wording tweak from Doug applied by me.

llvm-svn: 125996
2011-02-18 23:59:51 +00:00
Chandler Carruth a8bea4b90e Initial steps to improve diagnostics when there is a NULL and
a non-pointer on the two sides of a conditional expression.

Patch by Stephen Hines and Mihai Rusu.

llvm-svn: 125995
2011-02-18 23:54:50 +00:00
Ted Kremenek a7ced2cb4c Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.
llvm-svn: 125821
2011-02-18 02:27:00 +00:00
Ted Kremenek 48d9626055 Add -Warray-bounds test showing how the warning currently interoperates with macros.
llvm-svn: 125781
2011-02-17 21:40:51 +00:00
Chandler Carruth 1af88f12a3 Enhance the array bounds checking to work for several other constructs,
especially C++ code, and generally expand the test coverage.

Logic adapted from a patch by Kaelyn Uhrain <rikka@google.com> and
another Googler.

llvm-svn: 125775
2011-02-17 21:10:52 +00:00
Chandler Carruth 22c7a79a1d Implement a sub-group of -Wconversion: -Wliteral-conversion. This
specifically targets literals which are implicitly converted, a those
are more often unintended and trivial to fix. This can be especially
helpful for diagnosing what makes 'const int x = 1e6' not an ICE.

Original patch authored by Jim Meehan with contributions from other
Googlers and a few cleanups from myself.

llvm-svn: 125745
2011-02-17 11:05:49 +00:00
Chandler Carruth 712563bba4 Implement -Wenum-compare, which warns when comparing two enums of
different types. We omit the warning when the enum types are anonymous.
Unlike GCC, this warning does not distinguish between C++ and C/ObjC for
controling whether it is on by default, it is always on by default.

Original patch contributed by Richard Trieu (@ Google), I fixed some
style issues, and cleaned it up for submission.

llvm-svn: 125739
2011-02-17 08:37:06 +00:00
Douglas Gregor b0f2ea9e9e When printing a qualified type, look through a substituted template
parameter type to see what's behind it, so that we don't end up
printing silly things like "float const *" when "const float *" would
make more sense. Also, replace the pile of "isa" tests with a simple
switch enumerating all of the cases, making a few more obvious cases
use prefix qualifiers.

llvm-svn: 125729
2011-02-17 06:52:25 +00:00
Matt Beaumont-Gay 956fc1cb81 Fix PR9025 and add a diagnostic (and sometimes a fixit) for an overloaded
function name used as the base of a member expression. Early feedback from
Chandler Carruth, and code review from Nick Lewycky.

llvm-svn: 125714
2011-02-17 02:54:17 +00:00
Ted Kremenek 197fcd4418 Fix assertion failure in -Warray-bounds on template parameters used as arrays.
llvm-svn: 125693
2011-02-16 23:39:09 +00:00
John McCall 909acf8209 Provide overload diagnostics when explicit casts involving class types fail.
PR8626.

llvm-svn: 125506
2011-02-14 18:34:10 +00:00
John McCall c146582e60 When parsing an out-of-line member function declaration, we must delay
access-control diagnostics which arise from the portion of the declarator
following the scope specifier, just in case access is granted by
friending the individual method.  This can also happen with in-line
member function declarations of class templates due to templated-scope
friend declarations.

We were really playing fast-and-loose before with this sort of thing,
and it turned out to work because *most* friend functions are in file
scope.  Making us delay regardless of context exposed several bugs with
how we were manipulating delay.  I ended up needing a concept of a
context that's independent of the declarations in which it appears,
and then I actually had to make some things save contexts correctly,
but delay should be much cleaner now.

I also encapsulated all the delayed-diagnostics machinery in a single
subobject of Sema;  this is a pattern we might want to consider rolling
out to other components of Sema.

llvm-svn: 125485
2011-02-14 07:13:47 +00:00
Fariborz Jahanian 42455ea935 Implement objective-c++'s block pointer type matching involving
types which are contravariance in argument types and covariance
in return types. // rdar://8979379.

llvm-svn: 125445
2011-02-12 19:07:46 +00:00
Argyrios Kyrtzidis 7dd856a76b For -Woverloaded-virtual take into account canonical methods. Fixes rdar://8979966 & http://llvm.org/PR9182.
llvm-svn: 125296
2011-02-10 18:13:41 +00:00
John McCall f768aa7613 Move the check that gives functions with unique-external types unique-external
linkage into Decl.cpp.  Disable this logic for extern "C" functions, because
the operative rule there is weaker.  Fixes rdar://problem/8898466

llvm-svn: 125268
2011-02-10 06:50:24 +00:00
John McCall 7a198cef04 When checking the 'weak' and 'weakref' attributes, look for non-external
linkage rather than the presence of the 'static' storage class specifier.
Fixes rdar://problem/8814626.

llvm-svn: 125126
2011-02-08 22:35:49 +00:00
John McCall 53c72e71cc Test case accidentally left out of my last commit.
llvm-svn: 125119
2011-02-08 22:28:39 +00:00
Argyrios Kyrtzidis 898fdbf82d In Sema::CheckShadow, get the DeclContext from the variable that we are checking
instead from the Scope; Inner scopes in bodies don't have DeclContexts associated with them.

Fixes http://llvm.org/PR9160 & rdar://problem/8966163.

llvm-svn: 125097
2011-02-08 18:21:25 +00:00
Ted Kremenek e6a12a97d4 Move uninitialized variable checking back under -Wuninitialized-experimental. It is clear from user feedback that this warning is not quite ready.
llvm-svn: 125007
2011-02-07 17:38:38 +00:00
Anton Yartsev 85129b8a86 pre/post ++/-- for AltiVec vectors. (with builtins-ppc-altivec.c failure fixed)
llvm-svn: 125000
2011-02-07 02:17:30 +00:00
Argyrios Kyrtzidis 3d3208675f When the out-of-line definition differs from the declaration in the return type,
say "out-of-line definition differ from the declaration in the return type" instead of
the silly "functions that differ only in their return type cannot be overloaded".

Addresses rdar://7980179.

llvm-svn: 124939
2011-02-05 05:54:49 +00:00
Ted Kremenek 6c9cd14bf9 Don't suggest -Wuninitialized fixits for uninitialized enum types.
llvm-svn: 124924
2011-02-05 01:18:18 +00:00
Argyrios Kyrtzidis 7272d9cf36 Implement -Woverloaded-virtual.
The difference with gcc is that it warns if you overload virtual methods only if
the method doesn't also override any method. This is to cut down on the number of warnings
and make it more useful like reported here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423.
If we want to warn that not all overloads are overriden we can have an additional
warning like -Wpartial-override.

-Woverloaded-virtual, unlike gcc, is added to -Wmost. Addresses rdar://8757630.

llvm-svn: 124805
2011-02-03 18:01:15 +00:00
Ted Kremenek b3dbe28e31 Based on user feedback, swap -Wuninitialized diagnostics to have the warning refer to the bad use, and the note to the variable declaration.
llvm-svn: 124758
2011-02-02 23:35:53 +00:00
Fariborz Jahanian a5cdc7ea0f Turn test for // rdar://8945175 into a sema test.
llvm-svn: 124748
2011-02-02 21:10:07 +00:00
Argyrios Kyrtzidis 83b797f490 Don't warn for -Wnon-virtual-dtor for dependent classes.
llvm-svn: 124735
2011-02-02 18:47:41 +00:00
Ted Kremenek ae022096db Remove redundant check to not warn for warn_equality_with_extra_parens if we are in a macro. This is checked twice.
llvm-svn: 124714
2011-02-02 02:20:30 +00:00
Ted Kremenek c358d9f305 Don't warn about extraneous '()' around a comparison if it occurs within a macro.
Macros frequently contain extra '()' to make instantiation less error prone.
This warning was flagging a ton of times on postgresql because of its use of macros.

llvm-svn: 124695
2011-02-01 22:36:09 +00:00
Argyrios Kyrtzidis f4f8278c95 Don't warn for "if ((a == b))" if the parens came from a macro. Thanks to Fariborz for the hint!
llvm-svn: 124689
2011-02-01 22:23:56 +00:00
Argyrios Kyrtzidis 582dd68541 For "if ((a == b))" only warn if 'a' is a modifiable l-value. Caught by John!
llvm-svn: 124675
2011-02-01 19:32:59 +00:00
Argyrios Kyrtzidis 8b6ec6870f Warn for "if ((a == b))" where the equality expression is needlessly wrapped inside parentheses.
It's highly likely that the user intended an assignment used as condition.

Addresses rdar://8848646.

llvm-svn: 124668
2011-02-01 18:24:22 +00:00
Douglas Gregor fa7781384e Implement access checking for the "delete" operator. Fixes PR9050,
from Alex Miller!

llvm-svn: 124663
2011-02-01 15:50:11 +00:00
Argyrios Kyrtzidis 33799caf6d Only warn for -Wnon-virtual-dtor for public destructors. Thanks to Benjamin Kramer for the hint!
llvm-svn: 124585
2011-01-31 17:10:25 +00:00
Douglas Gregor 205d5e3a51 Implement the suggested resolution to core issue 547, extended to also
allow ref-qualifiers on function types used as template type
arguments. GNU actually allows cv-qualifiers on function types in many
places where it shouldn't, so we currently categorize this as a GNU
extension.

llvm-svn: 124584
2011-01-31 16:09:46 +00:00
Argyrios Kyrtzidis 7f3986dc64 Warn if the class has virtual methods but non-virtual destructor. Addresses rdar://8756445.
llvm-svn: 124582
2011-01-31 07:05:00 +00:00
Argyrios Kyrtzidis f46cc65f44 Don't warn that variables in C++ static member functions shadow fields. Fixes rdar://8900456.
llvm-svn: 124581
2011-01-31 07:04:54 +00:00
Argyrios Kyrtzidis 77fd99f8ae If there were errors, disable 'unused' warnings since they will mostly be noise.
Fixes rdar://8736362.

llvm-svn: 124577
2011-01-31 07:04:37 +00:00
Argyrios Kyrtzidis b85cd7c312 Error for use of field from anonymous struct or union should say "invalid use of nonstatic data member"
not "call to non-static member function without an object argument".

llvm-svn: 124576
2011-01-31 07:04:33 +00:00
John McCall 388ef53234 Fix some corner cases in the __is_base_of logic.
llvm-svn: 124505
2011-01-28 22:02:36 +00:00
Douglas Gregor c03a1083af Give OpaqueValueExpr a source location, because its source location
might be queried in places where we absolutely require a valid
location (e.g., for template instantiation). Fixes some major
brokenness in the use of __is_convertible_to.

llvm-svn: 124465
2011-01-28 02:26:04 +00:00
Douglas Gregor edb7685712 Teach the evaluation of the __is_convertible_to trait to translate
access control errors into SFINAE errors, so that the trait provides
enough support to implement the C++0x std::is_convertible type trait.

To get there, the SFINAETrap now knows how to set up a SFINAE context
independent of any template instantiations or template argument
deduction steps, and (separately) can set a Sema flag to translate
access control errors into SFINAE errors. The latter can also be
useful if we decide that access control errors during template argument
deduction should cause substitution failure (rather than a hard error)
as has been proposed for C++0x.

llvm-svn: 124446
2011-01-27 22:31:44 +00:00
Douglas Gregor 8006e76b4e Implement the Microsoft __is_convertible_to type trait, modeling the
semantics after the C++0x is_convertible type trait. This
implementation is not 100% complete, because it allows access errors
to be hard errors (rather than just evaluating false).

Original patch by Steven Watanabe!

llvm-svn: 124425
2011-01-27 20:28:01 +00:00
Jeffrey Yasskin bbc4eea2c2 Revert r124217 because it didn't catch the actual error case it was trying to
catch:

  lock_guard(my_mutex);

declares a variable instead of creating a temporary.

llvm-svn: 124398
2011-01-27 19:17:54 +00:00
Ted Kremenek 5d068499a7 Teach -Wreturn-type that destructors can appear
after a 'return' in a CFGBlock.  This accidentally
was working before, but the false assumption that
'return' always appeared at the end of the block
was uncovered by a recent change.

llvm-svn: 124280
2011-01-26 04:49:52 +00:00
Ted Kremenek e543be3531 Merge -Wuninitialized-experimental into -Wuninitialized.
llvm-svn: 124279
2011-01-26 04:49:48 +00:00
Argyrios Kyrtzidis cd81fe033c Fix infinite loop during error diagnostics. Fixes rdar://8875304.
llvm-svn: 124243
2011-01-25 23:16:36 +00:00
Ted Kremenek 4fd3fda33b Tweak return-noreturn.cpp test to have its original
contents, with the additional warning flag (and still marked XFAIL).

llvm-svn: 124239
2011-01-25 22:57:41 +00:00
Ted Kremenek ebe6260137 Fix regression in -Wreturn-type caused by not
handling all CFGElement kinds.  While writing
the test case, it turned out that return-noreturn.cpp
wasn't actually testing anything since it has the wrong -W
flag.  That uncovered another regression with
the handling of destructors marked noreturn.  WIP.

llvm-svn: 124238
2011-01-25 22:50:47 +00:00
Jeffrey Yasskin 08a4f8f197 Add an attribute to forbid temporary instances of a type. This allows class
authors to write 

  class __attribute__((forbid_temporaries)) Name { ... };

when they want to force users to name all variables of the type. This protects
people from doing things like creating a scoped_lock that only lives for a
single statement instead of an entire scope.

The warning produced by this attribute can be disabled by
-Wno-forbid-temporaries.

llvm-svn: 124217
2011-01-25 20:08:12 +00:00
Eric Christopher 23ec82fa47 Revert r124146 for now. It appears to be failing on a few platforms.
llvm-svn: 124153
2011-01-24 23:07:03 +00:00
Anton Yartsev 3bad9afaba pre/post increase/decrease for AltiVec vectors
llvm-svn: 124146
2011-01-24 20:55:22 +00:00
Nick Lewycky 0c4380856b Enhance the diagnostic for referring to a typedef with an elaborated name to be
as useful in a templated context as it is without templates. Fixes PR8755!

llvm-svn: 124136
2011-01-24 19:01:04 +00:00
Douglas Gregor f143cd5051 Re-instate r123977/r123978, my updates of the reference-binding
implementation used by overload resolution to support rvalue
references. The original commits caused PR9026 and some
hard-to-reproduce self-host breakage.

The only (crucial!) difference between this commit and the previous
commits is that we now properly check the SuppressUserConversions flag
before attempting to perform a second user-defined conversion in
reference binding, breaking the infinite recursion chain of
user-defined conversions.

Rvalue references should be working a bit better now.

llvm-svn: 124121
2011-01-24 16:14:37 +00:00
Anders Carlsson 571e2ad042 Mark VTables and RTTI data linkonce_odr instead of weak_odr, with the exception of explicit template instantiations, which have to be weak_odr.
This fixes PR6996.

llvm-svn: 124089
2011-01-24 00:46:19 +00:00
Anders Carlsson e30621b626 Get rid of [[hiding]], [[override]] and [[base_check]].
llvm-svn: 124087
2011-01-23 21:33:18 +00:00
Anders Carlsson 19588aa40b Get rid of the [[final]] C++0x attribute.
llvm-svn: 124083
2011-01-23 21:07:30 +00:00
Rafael Espindola b53c03be8a Add test from PR9026.
llvm-svn: 124034
2011-01-22 15:34:07 +00:00
Rafael Espindola be468d9a2b revert r123977 and r123978 to fix PR9026.
llvm-svn: 124033
2011-01-22 15:32:35 +00:00
Douglas Gregor 3f9047e321 Add a test for "perfect" forwarding
llvm-svn: 124005
2011-01-21 22:52:47 +00:00
Ted Kremenek 33d4b5eb66 Provide -Wuninitialized-experimental fixits
for floats, and also check if 'nil' is declared
when suggesting it for initializing ObjC pointers.

llvm-svn: 124004
2011-01-21 22:49:49 +00:00
Ted Kremenek 39fa056342 Enhance -Wuninitialized-experimental diagnostics
to issue the warning at an uninitialized variable's
declaration, but to issue notes at possible
uninitialized uses (which could be multiple).

llvm-svn: 123994
2011-01-21 19:41:41 +00:00
Douglas Gregor f282a76fab Implement the preference for move-construction over copy-construction
when returning an NRVO candidate expression. For example, this
properly picks the move constructor when dealing with code such as

  MoveOnlyType f() { MoveOnlyType mot; return mot; }

The previously-XFAIL'd rvalue-references test case now works, and has
been moved into the appropriate paragraph-specific test case.

llvm-svn: 123992
2011-01-21 19:38:21 +00:00
Douglas Gregor bf2f961a35 Add unique_ptr example to test the use of rvalue references. I'll grow
this example further as more rvalue-reference features come online.

llvm-svn: 123980
2011-01-21 17:06:29 +00:00
Douglas Gregor 95273c3a22 Update the reference-binding implementation used for overload
resolution to match the latest C++0x working paper's semantics. The
implementation now matching up with the reference-binding
implementation used for initialization.

llvm-svn: 123977
2011-01-21 16:36:05 +00:00
Douglas Gregor bed28f7629 Improve the diagnostic that complains about binding an rvalue
reference to an lvalue.

llvm-svn: 123953
2011-01-21 01:04:33 +00:00
Douglas Gregor 24f2e8ec00 More work to bring reference binding up to the latest C++0x
specification. In particular, an rvalue reference can bind to an
initializer expression that is an lvalue if the referent type and the
initializer expression type are not reference-related. This is a newer
formulation to the previous "rvalue references can never bind to
lvalues" rule.

llvm-svn: 123952
2011-01-21 00:52:42 +00:00
Ted Kremenek cdca8fa97d Relax CFG assertions in UninitializedValuesV2 when
handling pseudo-path sensitivity, and instead
use those assertion conditions as dynamic checks.
These assertions would be violated when analyzing
a CFG where some branches where optimized away
during CFG construction because their branch
conditions could be trivially determined.

llvm-svn: 123943
2011-01-20 21:25:31 +00:00
Rafael Espindola ec4b30a1e8 Merge test.
llvm-svn: 123914
2011-01-20 16:11:21 +00:00
Rafael Espindola 4b6053a1fe Turns out that the previous commit also fixes this :-)
llvm-svn: 123873
2011-01-20 02:57:51 +00:00
Rafael Espindola 9e976dcce8 Fix PR8884 by skipping transparent contexts. The test is for LikageSpec. I
failed to find a case where an enum context would make a difference, but
found PR9007 on the way.

llvm-svn: 123871
2011-01-20 02:26:24 +00:00
Douglas Gregor 668443efb1 Sema::BuildCXXMemberCallExpr() can fail due to access or ambiguities,
so allow it to propagate the failure outward. Fixes the crashing part
of <rdar://problem/8876150>.

llvm-svn: 123863
2011-01-20 00:18:04 +00:00
Douglas Gregor 2d4f64f441 Warn about the use of unparenthesized |= in conditionals (which may be
a typo for !=). Fixes PR9001, from Hans Wennborg!

llvm-svn: 123836
2011-01-19 16:50:08 +00:00