Commit Graph

1687 Commits

Author SHA1 Message Date
Abramo Bagnara dd8fc04e9b Fixed PR10243.
llvm-svn: 134892
2011-07-11 08:52:40 +00:00
John McCall 21878760a4 Fixed enum types can be complete without actually being valid to use
as scope specifiers;  diagnose the attempt, rather than letting it go
to an assert.  The rest of PR10264.

llvm-svn: 134479
2011-07-06 06:57:57 +00:00
John McCall cb432faf6d Properly protect colons when parsing a nested-name-specifier as part
of an enum specifier in dialects which permit fixed underlying types.
Fixes the rejects-valid part of PR10264.

llvm-svn: 134468
2011-07-06 05:58:41 +00:00
Douglas Gregor 1fe12c9eba ActOnCXXConditionDeclaration should take into account that
ActOnDeclarator can return NULL. Fixes PR10270, from Hans Wennborg!

llvm-svn: 134416
2011-07-05 16:13:20 +00:00
Richard Trieu 94942b32a3 For code such as:
int f(int x) {
  if (int foo = f(bar)) {}
  return 0;
}

Clang produces the following error messages:

paren_imbalance.cc:2:19: error: use of undeclared identifier 'bar'
  if (int foo = f(bar)) {}
                  ^
paren_imbalance.cc:2:26: error: expected ')'
  if (int foo = f(bar)) {}
                        ^
paren_imbalance.cc:2:6: note: to match this '('
  if (int foo = f(bar)) {}
     ^

The second error is incorrect.  This patch will stop Clang from producing an error on parenthesis imbalance during error recovery when there isn't one.

llvm-svn: 134258
2011-07-01 20:54:02 +00:00
Richard Trieu 95d880933b Fix for PR7410. Allow functions in a derived class that improperly overwrite a virtual function in the base class to be inserted into the derived class function list to prevent extra errors every time the derived class is used.
llvm-svn: 134251
2011-07-01 20:02:53 +00:00
Hans Wennborg de7a9c2415 Move test/Sema/return.cpp into test/SemaCXX/return.cpp
llvm-svn: 134171
2011-06-30 17:20:18 +00:00
John McCall 0b645e9030 Perform lvalue-to-rvalue conversions on both operands of ->*
and the RHS of .*.  Noticed by Enea Zaffanella!

llvm-svn: 134170
2011-06-30 17:15:34 +00:00
Douglas Gregor c2fa169d6c Add support for C++ namespace-aware typo correction, e.g., correcting
vector<int>

to

  std::vector<int>

Patch by Kaelyn Uhrain, with minor tweaks + PCH support from me. Fixes
PR5776/<rdar://problem/8652971>.

Thanks Kaelyn!

llvm-svn: 134007
2011-06-28 16:20:02 +00:00
Argyrios Kyrtzidis 8ea7e5838b Remove the call to GetTypeForDeclarator in Sema::ActOnCXXConditionDeclaration.
No functionality change.

llvm-svn: 133984
2011-06-28 03:01:12 +00:00
Argyrios Kyrtzidis 31daf43c2b Cut down a few of the excess errors in the test.
llvm-svn: 133983
2011-06-28 03:01:09 +00:00
John McCall 1ee9fc02c9 Update test for r133934.
llvm-svn: 133942
2011-06-27 21:23:26 +00:00
Chandler Carruth 5925926a2f Fix missing braces around two statements that were intended to be part
of a single if block. This is really annoying to track down and test.
Silly changes to the test case caused it to stop showing up. I wish
there were a more concrete way of asserting that a note attaches to the
intended diagnostic.

This fixes PR10195.

llvm-svn: 133907
2011-06-27 08:31:58 +00:00
Chandler Carruth c933221826 Factor out (some of) the checking for invalid forms of pointer
arithmetic into a couple of common routines. Use these to make the
messages more consistent in the various contexts, especially in terms of
consistently diagnosing binary operators with invalid types on both the
left- and right-hand side. Also, improve the grammar and wording of the
messages some, handling both two pointers and two (different) types.

The wording of function pointer arithmetic diagnostics still strikes me
as poorly phrased, and I worry this makes them slightly more awkward if
more consistent. I'm hoping to fix that with a follow-on patch and test
case that will also make them more helpful when a typedef or template
type parameter makes the type completely opaque.

Suggestions on better wording are very welcome, thanks to Richard Smith
for some initial help on that front.

llvm-svn: 133906
2011-06-27 08:02:19 +00:00
Richard Smith cfcdf3a659 Fix a couple more issues related to r133854:
When performing semantic analysis on a member declaration, fix the check for whether we are declaring a function to check for parenthesized declarators, declaration via decltype, etc.

Also fix the semantic check to not treat FuncType* as a function type.

llvm-svn: 133862
2011-06-25 02:28:38 +00:00
Douglas Gregor c15b0cfc1f When deciding how to parse "= something" as part of a member
declaration, determine whether the declaration will end up declaring a
function using semantic criteria (e.g., it will have function type)
rather than purely syntactic criteria (e.g., it has the form of a
function declarator). Fixes <rdar://problem/9670557>.

llvm-svn: 133854
2011-06-25 00:56:27 +00:00
Argyrios Kyrtzidis d8a2771109 Only do delayed diagnostics if there were no errors when parsing the decl.
Fixes crash in http://llvm.org/PR10109 & rdar://9584039.

llvm-svn: 133816
2011-06-24 19:59:27 +00:00
Alexis Hunt 1da39282ec This patch started as an attempt to fix up the horrid naming
conventions. I then discovered a typo in the using declaration bit in
LookupSpecialMember. This led to discovering [namespace.udecl]p15, which
clang implements incorrectly. Thus I've added a comment and implemented
the code consistently with the rest of clang - that is incorrectly.

And because I don't want to include tests of something incorrect, I've
ripped the test out.

llvm-svn: 133784
2011-06-24 02:11:39 +00:00
Eli Friedman 1408bc9a55 Fix Sema::CheckVectorOperands so that it doesn't try to insert a cast expression into the LHS of a compound assignment. Fixes compound assignment of various "compatible" vector types, including NEON-vector and gcc-vector types.
<rdar://problem/9640356>

llvm-svn: 133737
2011-06-23 18:10:35 +00:00
Argyrios Kyrtzidis ab72b6792b Allow unavailable function calls inside unavailable functions in C++/ObjC++ as well. rdar://9660196
llvm-svn: 133672
2011-06-23 00:41:50 +00:00
Alexis Hunt 080709f82d Clean up the heart of the caching code and miss fewer edge cases.
llvm-svn: 133671
2011-06-23 00:26:20 +00:00
Douglas Gregor 835af98597 Check for placeholders early on in
Sema::CreateUnaryExprOrTypeTraitExpr() rather than recursing in some
cases. Fixes <rdar://problem/9659191>.

llvm-svn: 133663
2011-06-22 23:21:00 +00:00
Richard Smith 2602a683e0 Fix PR10168: don't warn for unused non-dependent variables in both the template definition and each instantiation.
llvm-svn: 133580
2011-06-21 23:42:09 +00:00
Richard Smith f9603354ea First part of PR9968: the __range variable in a dependent C++11 for-range statement is implicitly used by that statement.
llvm-svn: 133572
2011-06-21 23:07:19 +00:00
Chandler Carruth 44d5c1e063 Use an explicitly 64-bit triple flag to ensure we can easily verify the
types printed in various diagnostics.

We could omit checking for the types, but that can mask errors where the
wrong type is streamed into the diagnostic. There was at least one of
these caught by this test already.

llvm-svn: 133429
2011-06-20 08:59:25 +00:00
Chandler Carruth 5f380da06f Fix a problem with the diagnostics of invalid arithmetic with function
pointers I found while working on the NULL arithmetic warning. We here
always assuming the LHS was the pointer, instead of using the selected
pointer expression.

llvm-svn: 133428
2011-06-20 07:52:11 +00:00
Chandler Carruth 4f04b436f8 Move away from the poor "abstraction" I added to Type. John argued
effectively that this abstraction simply doesn't exist. That is
highlighted by the fact that by using it we were papering over a more
serious error in this warning: the fact that we warned for *invalid*
constructs involving member pointers and block pointers.

I've fixed the obvious issues with the warning here, but this is
confirming an original suspicion that this warning's implementation is
flawed. I'm looking into how we can implement this more reasonably. WIP
on that front.

llvm-svn: 133425
2011-06-20 07:38:51 +00:00
Chandler Carruth e1db1cf0c3 Add test cases for false positives on -Wnull-arithmetic from Richard
Trieu, and fix them by checking for array and function types as well as
pointer types.

I've added a predicate method on Type to bundle together the logic we're
using here: isPointerLikeType(). I'd welcome better names for this
predicate, this is the best I came up with. It's implemented as a switch
to be a touch lighter weight than all the chained isa<...> casts that
would result otherwise.

llvm-svn: 133383
2011-06-19 09:05:14 +00:00
Francois Pichet e878cb6bd1 Handle decltype keyword in Parser::isDeclarationSpecifier.
Fixes PR10154. Found by parsing MFC 2010 code with clang.

llvm-svn: 133380
2011-06-19 08:02:06 +00:00
Richard Trieu fc51bc1cea Put the new warning from revision 133196 on NULL arithmetic behind the flag -Wnull-arthimetic and set to DefaultIgnore. A few edge cases need to be worked out before this can be set to default.
llvm-svn: 133287
2011-06-17 20:35:48 +00:00
Douglas Gregor cbd446d325 Check for placeholder expressions before promoting an argument passed
through an ellipsis. Fixes <rdar://problem/9623945>.

llvm-svn: 133219
2011-06-17 00:15:10 +00:00
Richard Trieu 701fb36b95 Add a new warning when a NULL constant is used in arithmetic operations. The warning will fire on cases such as:
int x = 1 + NULL;

llvm-svn: 133196
2011-06-16 21:36:56 +00:00
Douglas Gregor 18739c343c Teach the warning about non-POD memset/memcpy/memmove to deal with the
__builtin_ versions of these functions as well as the normal function
versions, so that it works on platforms where memset/memcpy/memmove
are macros that map down to the builtins (e.g., Darwin). Fixes
<rdar://problem/9372688>.

llvm-svn: 133173
2011-06-16 17:56:04 +00:00
Chandler Carruth 8b9e5a72cb Rework the warning for 'memset(p, 0, sizeof(p))' where 'p' is a pointer
and the programmer intended to write 'sizeof(*p)'. There are several
elements to the new version:

1) The actual expressions are compared in order to more accurately flag
   the case where the pattern that works for an array has been used, or
   a '*' has been omitted.
2) Only do a loose type-based check for record types. This prevents us
   from warning when we happen to be copying around chunks of data the
   size of a pointer and the pointer types for the sizeof and
   source/dest match.
3) Move all the diagnostics behind the runtime diagnostic filter. Not
   sure this is really important for this particular diagnostic, but
   almost everything else in SemaChecking.cpp does so.
4) Make the wording of the diagnostic more precise and informative. At
   least to my eyes.
5) Provide highlighting for the two expressions which had the unexpected
   similarity.
6) Place this diagnostic under a flag: -Wsizeof-pointer-memaccess

This uses the Stmt::Profile system for computing #1. Because of the
potential cost, this is guarded by the warning flag. I'd be interested
in feedback on how bad this is in practice; I would expect it to be
quite cheap in practice. Ideas for a cheaper / better way to do this are
also welcome.

The diagnostic wording could likely use some further wordsmithing.
Suggestions welcome here. The goals I had were to: clarify that its the
interaction of 'memset' and 'sizeof' and give more reasonable
suggestions for a resolution.

An open question is whether these diagnostics should have the note
attached for silencing by casting the dest/source pointer to void*.

llvm-svn: 133155
2011-06-16 09:09:40 +00:00
Chandler Carruth 30f3210242 Fix my test case from r133136 so that it actually represents the code
pattern found in the wild where this warning was firing.

llvm-svn: 133143
2011-06-16 04:13:47 +00:00
Chandler Carruth a05e09ba48 Skip both character pointers and void pointers when diagnosing bad
argument types for mem{set,cpy,move}. Character pointers, much like void
pointers, often point to generic "memory", so trying to check whether
they match the type of the argument to 'sizeof' (or other checks) is
unproductive and often results in false positives.

Nico, please review; does this miss any of the bugs you were trying to
find with this warning? The array test case you had should be caught by
the array-specific sizeof warning I think.

llvm-svn: 133136
2011-06-16 02:00:04 +00:00
Nico Weber 50340d5c87 Build fix attempt.
llvm-svn: 133039
2011-06-15 04:50:13 +00:00
Nico Weber c5e7386983 Warn on memset(ptr, 0, sizeof(ptr)). Diagnostic wording by Jordy Rose.
llvm-svn: 132996
2011-06-14 16:14:58 +00:00
Chris Lattner f35de48c90 when compiling in a GNU mode (e.g. gnu99) treat VLAs with a size that can be folded to a constant
as constant size arrays.  This has slightly different semantics in some insane cases, but allows
us to accept some constructs that GCC does.  Continue to be pedantic in -std=c99 and other
modes.  This addressed rdar://8733881 - error "variable-sized object may not be initialized"; g++ accepts same code

llvm-svn: 132983
2011-06-14 06:38:10 +00:00
Chris Lattner 9925ec8bf4 fix rdar://9204520 - Accept int(0.85 * 10) as an initializer in a class member
as an extension.

llvm-svn: 132980
2011-06-14 05:46:29 +00:00
David Majnemer c75d1a1098 Properly diagnose using abstract and incomplete types in va_arg
- Move a test from test/SemaTemplate/instantiate-expr-3.cpp, it did not belong there
- Incomplete and abstract types are considered hard errors

llvm-svn: 132979
2011-06-14 05:17:32 +00:00
Richard Smith 4a4beec7b0 Don't assert on initialized typedef declarations in classes:
struct {
    typedef int A = 0;
  };

According to the C++11 standard, this is not ill-formed, but does not have any ascribed meaning. We can't reasonably accept it, so treat it as ill-formed.

Also switch C++ from an incorrect 'fields can only be initialized in constructors' diagnostic for this case to C's 'illegal initializer (only variables can be initialized)'

llvm-svn: 132890
2011-06-12 11:43:46 +00:00
Richard Smith 938f40b5aa Implement support for C++11 in-class initialization of non-static data members.
llvm-svn: 132878
2011-06-11 17:19:42 +00:00
Alexis Hunt 387e6d5dc6 Uncomment this testcase now that we pass it.
llvm-svn: 132842
2011-06-10 09:32:33 +00:00
Richard Trieu caa33d36fb Made changes to how 'struct'/'class' mismatches are handled in -Wmismatched-tags.
- Removed fix-it hints from template instaniations since changes to the
templates are rarely helpful.
- Changed the caret in template instaniations from the class/struct name to the
class/struct keyword, matching the other warnings.
- Do not offer fix-it hints when multiple declarations disagree.  Warnings are
still given.
- Once a definition is found, offer a fix-it hint to all previous declarations
with wrong tag.
- Declarations that disagree with a previous definition will get a fix-it hint
to change the declaration.

llvm-svn: 132831
2011-06-10 03:11:26 +00:00
Eli Friedman 9ed3cde1fa Start fixing up clang tests to work on the clang-native-arm-cortex-a9 builder.
llvm-svn: 132691
2011-06-06 21:23:05 +00:00
Sebastian Redl f08872fb29 More std::initializer_list tests.
llvm-svn: 132663
2011-06-05 12:23:21 +00:00
Sebastian Redl 3da3489e49 Parse C++0x generalized initializers.
llvm-svn: 132662
2011-06-05 12:23:16 +00:00
Sebastian Redl 144857f4cc Expand on braced init list tests.
llvm-svn: 132661
2011-06-05 12:23:08 +00:00
Douglas Gregor 377c109f21 Identity and non-identity standard conversion sequences can be
compared even when one is a reference binding and the other is not
(<rdar://problem/9173984>), but the definition of an identity sequence
does not involve lvalue-to-rvalue adjustments (PR9507). Fix both
inter-related issues.

llvm-svn: 132660
2011-06-05 06:15:20 +00:00
Alexis Hunt 6fc542c49b I've had too much to drink, apparently.
llvm-svn: 132566
2011-06-03 18:05:29 +00:00
Alexis Hunt ea31988f63 Implement a warning flag for the warning about default arguments making
special member functions.

llvm-svn: 132564
2011-06-03 17:55:52 +00:00
Hans Wennborg 0bb0df5839 Make -Wignored-qualifiers point to the first ignored qualifier.
In code such as "char* volatile const j()", Clang warns that "volatile
const" will be ignored. Make it point to the first ignored qualifier,
and simplify the code a bit.

llvm-svn: 132563
2011-06-03 17:37:26 +00:00
Chandler Carruth ac6872655b Clean up the "non-POD memaccess" stuff some. This adds a properly named
diagnostic group to cover the cases where we have definitively bad
behavior: dynamic classes.

It also rips out the existing support for POD-based checking. This
didn't work well, and triggered too many false positives. I'm looking
into a possibly more principled way to warn on the fundamental buggy
construct here. POD-ness isn't the critical aspect anyways, so a clean
slate is better. This also removes some silliness from the code until
the new checks arrive.

llvm-svn: 132534
2011-06-03 06:23:57 +00:00
Nick Lewycky 1be750abc6 Even a return statement of an expression with a dependent type in a void
function might need to clean up its temporaries. Fixes PR10057.

llvm-svn: 132390
2011-06-01 07:44:31 +00:00
Francois Pichet e37eebabe7 Microsoft friend acting as a forward declaration; try#2. Now only 2 lines.
llvm-svn: 132387
2011-06-01 04:14:20 +00:00
Francois Pichet a9f436b064 Revert 132332 (Microsoft friend as a forward declaration), John McCall pointed out a better/simpler way to do it.
llvm-svn: 132369
2011-05-31 22:36:05 +00:00
Alexis Hunt 414e3e3c2d Ensure we enter an unevaluated context when instantiating a noexcept
expression. Fixes bug raised by hhinnant to cfe-dev

llvm-svn: 132350
2011-05-31 19:54:49 +00:00
Francois Pichet 3fd47df366 For compatibility with MSVC, a friend declaration also act as a forward declaration if the tag name is not already declared. The tag name is declared in the next outermost non record scope.
Example:

class A {
  friend class B;
  B* b;
};
B* global_b;

llvm-svn: 132332
2011-05-31 11:44:00 +00:00
Nick Lewycky 67c4d0f336 Whenever we instantiate a static data member, make sure to define any new
vtables! Fixes PR10020

This also allows us to revert the part of r130023 which added a big loop around
the template instantiation.

llvm-svn: 132331
2011-05-31 07:58:42 +00:00
Chandler Carruth e54ff6cc3e Expand the coverage of the warning for constants on the RHS of logical operands:
return f() || -1;

where the user meant to write '|'.

This bootstraps without any additional warnings.

Patch by Richard Trieu.

llvm-svn: 132327
2011-05-31 05:41:42 +00:00
Richard Trieu beaf34531e Add a new warning on NULL pointer constant to integer conversion.
This path was reviewed by Chandler Carruth at http://codereview.appspot.com/4538074/

llvm-svn: 132297
2011-05-29 19:59:02 +00:00
Alexis Hunt d051b87160 Implement a new warning for when adding a default argument to a method
makes it into a special member function. This is very bad and can lead
to all sorts of nastiness including implicit member functions violating
the One Definition Rule. This should probably be made ill-formed in a
later version of the standard, but for now we'll just warn.

llvm-svn: 132104
2011-05-26 01:26:05 +00:00
Alexis Hunt e852b100e2 Implement a new type node, UnaryTransformType, designed to represent a
type that turns one type into another. This is used as the basis to
implement __underlying_type properly - with TypeSourceInfo and proper
behavior in the face of templates.

llvm-svn: 132017
2011-05-24 22:41:36 +00:00
Argyrios Kyrtzidis 8bd428574c Add new warning that warns when invoking 'delete' on a polymorphic, non-final, class without a virtual destructor.
Patch by Matthieu Monrocq!

llvm-svn: 131989
2011-05-24 19:53:26 +00:00
Chandler Carruth 0dc3f8db1a Fix a bug in -Wundefined-reinterpret-cast where we failed to look
through sugared types when testing for TagTypes. This was the actual
cause of the only false positive in Clang+LLVM.

Next evaluation will be over a much larger selection of code including
large amounts of open source code.

llvm-svn: 131957
2011-05-24 07:43:19 +00:00
Francois Pichet a8032e96b5 MSVC doesn't do any validation regarding exception specification.
llvm-svn: 131950
2011-05-24 02:11:43 +00:00
Francois Pichet efb1af9ae8 Emulate a MSVC bug where if during an using declaration name lookup, the declaration found is unaccessible (private) and that declaration was bring into scope via another using declaration whose target declaration is accessible (public) then no error is generated.
Example:
class A { public: int f();  };
class B : public A { private: using A::f; };
class C : public B { private: using B::f; };

Here, B::f is private so this should fail in Standard C++, but because B::f refers to A::f which is public MSVC accepts it.

This fixes 1 error when parsing MFC code with clang.

llvm-svn: 131896
2011-05-23 03:43:44 +00:00
Douglas Gregor 80af31397a Audit and finish the implementation of C++0x nullptr, fixing two
minor issues along the way:
  - Non-type template parameters of type 'std::nullptr_t' were not
  permitted.
  - We didn't properly introduce built-in operators for nullptr ==,
  !=, <, <=, >=, or > as candidate functions .

To my knowledge, there's only one (minor but annoying) part of nullptr
that hasn't been implemented: catching a thrown 'nullptr' as a pointer
or pointer-to-member, per C++0x [except.handle]p4.

llvm-svn: 131813
2011-05-21 23:15:46 +00:00
Douglas Gregor b7c36f6c68 Classify bound member function types are member function types. Fixes
PR9973 / <rdar://problem/9479191>.

llvm-svn: 131810
2011-05-21 21:04:55 +00:00
Douglas Gregor 347e0f26be Fix our handling of the warning when one tries to pass a
non-POD/non-trivial object throuugh a C-style varargs. The warning
itself was default-mapped to error, but can be downgraded, but we were
treating it in Sema like a hard error, silently dropping the call.

Instead, treat this problem like a warning, and do what the warning
says we do: abort at runtime. To do so, we fake up a __builtin_trap()
expression that gets evaluated as part of the argument.

llvm-svn: 131805
2011-05-21 19:26:31 +00:00
Alexis Hunt a671bca618 Add a missing case for default constructor deletion.
This case is tested by the fact that the modified test produces
significatly worse diagnostics. That's on the list.

llvm-svn: 131759
2011-05-20 21:43:47 +00:00
Sebastian Redl d29f6086a4 Introduce XFAILed test for braced initializer lists.
llvm-svn: 131754
2011-05-20 21:07:01 +00:00
Eli Friedman 023416f73c Fix test on Windows.
llvm-svn: 131691
2011-05-19 22:39:47 +00:00
Alexis Hunt cf5f2f41ba Add a test for __underlying_type
llvm-svn: 131670
2011-05-19 20:36:08 +00:00
Sebastian Redl 623ea82a6b Reapply r121528, fixing PR9941 by delaying the exception specification check for destructors until the class is complete and destructors have been adjusted.
llvm-svn: 131632
2011-05-19 05:13:44 +00:00
Alexis Hunt d0cdd1fab1 Revert r121528 as it breaks a simple testcase, which leads to, among
other things, libcxx not building.

llvm-svn: 131573
2011-05-18 20:57:11 +00:00
Alexis Hunt e77a28f7e1 Implement an additional fix for infinite recursion of deleted special
member functions by making sure that they're on the record before
checking for deletion.

Also make sure source locations are valid to avoid crashes.

Unfortunately, the declare-all-implicit-members approach is still
required in order to ensure that dependency loops do not result in
incorrectly deleting functions (since they are to be deleted at the
declaration point per the standard).

Fixes PR9917

llvm-svn: 131520
2011-05-18 03:41:58 +00:00
Alexis Hunt 604aeb3849 Fix some minor bugs and add a lot more test cases for defaulted
constructors, including two more FIXMEs (one of which I don't actually
understand).

llvm-svn: 131487
2011-05-17 20:44:43 +00:00
Alexis Hunt fa7afe2a05 Add some more tests.
I have on that's #if 0'ed out, and I don't know why it's failing to
delete the constructor. I'd appreciate if someone familiar with access
control could look into ShouldDeleteDefaultConstructor - thanks.

llvm-svn: 131486
2011-05-17 20:44:39 +00:00
Alexis Hunt 8b4551844c Implement some tests for defaulted constructors. To do this I had to
suppress an error we were previously emitting on valid union code.

llvm-svn: 131440
2011-05-17 00:19:05 +00:00
Alexis Hunt 97ab554c1c Implement the new C++0x rules for non-trivial things in unions so that
my defaulted constructor tests stop yelling at me about them.

llvm-svn: 131432
2011-05-16 22:41:40 +00:00
Francois Pichet c2fac71c75 Revert 131347. It asserts if the specialization in within a class template:
template<class U> 
struct X1 {
  template<class T> void f(T*);
  template<> void f(int*) { } 
};

Won't be so simple. I need to think more about it.

llvm-svn: 131362
2011-05-14 19:17:07 +00:00
Francois Pichet 6744e14d9c In Microsoft mode, allow template function explicit specialization at class scope.
Necessary to parse MFC and MSVC standard lib code.

Example:
struct X {
  template<class T> void f(T) { }
  template<> void f(int) { } 
}

llvm-svn: 131347
2011-05-14 17:46:46 +00:00
Richard Smith 0c4a34b1a0 PR9908: Fix the broken fix for PR9902 to get the template argument lists in the right order.
Also, don't reject alias templates in all ElaboratedTypes: some ElaboratedTypes do not correspond to elaborated-type-specifiers.

llvm-svn: 131342
2011-05-14 15:04:18 +00:00
Alexis Hunt 94f9cbf998 Implement a few basic tests for defaulted and deleted functions.
More comprehensive testing once copy {constructors,assignment operators}
can be defaulted.

llvm-svn: 131275
2011-05-13 01:01:05 +00:00
Alexis Hunt d9a5cc13cf Implement the __is_trivially_copyable type trait
llvm-svn: 131270
2011-05-13 00:31:07 +00:00
Richard Smith 5e96d8328d Fix PR9902: correctly substitute alias templates within the template in which they are defined: provide an empty list of arguments for each containing template context during substitution.
llvm-svn: 131211
2011-05-12 00:06:17 +00:00
Francois Pichet b796b632a8 In Microsoft mode, allow conversion from pointer to integral type no matter what size the integral type is. Necessary to parse MFC code.
Example:
void f(char *ptr) {
  char var = (char)ptr;
}

llvm-svn: 131201
2011-05-11 22:13:54 +00:00
John McCall c67067f43e Teach CFG building how to deal with CXXMemberCallExprs and BoundMemberTy,
then teach -Wreturn-type to handle the same.  Net effect:  we now correctly
handle noreturn attributes on member calls in the CFG.

llvm-svn: 131178
2011-05-11 07:19:11 +00:00
Alexis Hunt 80f00ff95d Re-do R131114 without breaking code.
I've edited one diagnostic which would print "copy constructor" for copy
constructors and "constructor" for any other constructor. If anyone is
extremely enamored with this, it can be reinstated with a simple boolean
flag rather than calling getSpecialMember, which is inappropriate.

llvm-svn: 131143
2011-05-10 19:08:14 +00:00
Rafael Espindola d9ddbb0807 Add test for PR9884.
llvm-svn: 131127
2011-05-10 14:19:13 +00:00
Douglas Gregor 0f8bc97abd Ignore const/volatile/restrict qualifiers on anonymous structs and
unions. Fixes PR8326.

llvm-svn: 131109
2011-05-09 23:05:33 +00:00
Douglas Gregor 5d1d9e381e Extend the tag-ambiguity hack I committed in r130810 for tag
definitions to also include tag declarations. Fixes PR8151.

llvm-svn: 131102
2011-05-09 21:46:33 +00:00
Alexis Hunt 88c75c311f Clean up trivial default constructors now.
hasTrivialDefaultConstructor() really really means it now.

Also implement a fun standards bug regarding aggregates. Doug, if you'd
like, I can un-implement that bug if you think it is truly a defect.

The bug is that non-special-member constructors are never considered
user-provided, so the following is an aggregate:

struct foo {
  foo(int);
};

It's kind of bad, but the solution isn't obvious - should

struct foo {
  foo (int) = delete;
};

be an aggregate or not?

Lastly, add a missing initialization to FunctionDecl.

llvm-svn: 131101
2011-05-09 21:45:35 +00:00
Francois Pichet a7c8da40a8 Fix test.
llvm-svn: 131077
2011-05-08 23:15:10 +00:00
Francois Pichet bc6ebb5b76 Allow implicit conversion from function pointer to void* in Microsoft mode.
Necessary to parse MFC code.

llvm-svn: 131076
2011-05-08 22:52:41 +00:00
Alexis Hunt 4a8ea1092a Modify some deleted function methods to better reflect reality:
- New isDefined() function checks for deletedness
 - isThisDeclarationADefinition checks for deletedness
 - New doesThisDeclarationHaveABody() does what
   isThisDeclarationADefinition() used to do
 - The IsDeleted bit is not propagated across redeclarations
 - isDeleted() now checks the canoncial declaration
 - New isDeletedAsWritten() does what it says on the tin.
 - isUserProvided() now correct (thanks Richard!)

This fixes the bug that we weren't catching

void foo() = delete;
void foo() {}

as being a redefinition.

llvm-svn: 131013
2011-05-06 20:44:56 +00:00
Anders Carlsson 47061ee5bc Warn when trying to call a pure virtual member function in a class from the class constructor/destructor. Fixes PR7966.
llvm-svn: 130982
2011-05-06 14:25:31 +00:00
Richard Smith 3f1b5d077b Implement support for C++0x alias templates.
llvm-svn: 130953
2011-05-05 21:57:07 +00:00
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