Commit Graph

864 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 2644063ec9 Pass context and access to Parser::ParseExplicitInstantiation() for
good parser error recovery and for not crashing.

We still have a accepts-invalid-code bug.

llvm-svn: 147216
2011-12-23 02:16:45 +00:00
Richard Smith ed2974f3cf C++ constant expression handling: eagerly instantiate static const integral data
members of class templates so that their values can be used in ICEs. This
required reverting r105465, to get such instantiated members to be included in
serialized ASTs.

llvm-svn: 147023
2011-12-21 00:25:33 +00:00
Richard Trieu 553b2b2e5d Modify how the -verify flag works. Currently, the verification string and
diagnostic message are compared.  If either is a substring of the other, then
no error is given.  This gives rise to an unexpected case:

  // expect-error{{candidate function has different number of parameters}}

will match the following error messages from Clang:

  candidate function has different number of parameters (expected 1 but has 2)
  candidate function has different number of parameters

It will also match these other error messages:

  candidate function
  function has different number of parameters
  number of parameters

This patch will change so that the verification string must be a substring of
the diagnostic message before accepting.  Also, all the failing tests from this
change have been corrected.  Some stats from this cleanup:

87 - removed extra spaces around verification strings
70 - wording updates to diagnostics
40 - extra leading or trailing characters (typos, unmatched parens or quotes)
35 - diagnostic level was included (error:, warning:, or note:)
18 - flag name put in the warning (-Wprotocol)

llvm-svn: 146619
2011-12-15 00:38:15 +00:00
Francois Pichet 025131601d Implement the Microsoft __if_exists/if_not_exists extension in initializer-list.
Necessary to parse Microsoft ATL code.

Example: 
  int array[] = {
    0, 
    __if_exists(CLASS::Type) {2, }
    3
  };

will declare an array of 2 or 3 elements depending on if CLASS::Type exists or not.

llvm-svn: 146447
2011-12-12 23:24:39 +00:00
David Blaikie 10eb4b67d8 Add notes for suppressing and (if it's a zero-arg function returning bool) fixing the function-to-bool conversion warning.
llvm-svn: 146280
2011-12-09 21:42:37 +00:00
Lang Hames df5c121f8e Add a warning for implicit conversion from function literals (and static
methods) to bool. E.g.

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

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

llvm-svn: 145849
2011-12-05 20:49:50 +00:00
Francois Pichet 9c39113fdb In Microsoft mode, don't perform typo correction in a template member function dependent context because it interferes with the "lookup into dependent bases of class templates" feature.
Basically typo correction will try to offer a correction instead of looking into type dependent base classes.

I found this problem while parsing Microsoft ATL code with clang.

llvm-svn: 145772
2011-12-03 15:55:29 +00:00
Francois Pichet de232cb166 In Microsoft mode, make "Unqualified lookup into dependent bases of class templates" works inside a friend function definition at class scope.
Basically we have to look into the parent *lexical* DeclContext for friend functions at class scope. That's because calling GetParent() return the namespace or file DeclContext.

This fixes all remaining cases of "Unqualified lookup into dependent bases of class templates" when parsing MFC code with clang.

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

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

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

llvm-svn: 145045
2011-11-21 19:36:32 +00:00
Francois Pichet 857f9d6e5e In Microsoft mode, make "Unqualified lookup into dependent bases of class templates" works inside default argument instantiation.
This is a little bit tricky because during default argument instantiation the CurContext points to a CXXMethodDecl but we can't use the keyword this or have an implicit member call generated.

This fixes 2 errors when parsing MFC code with clang.

llvm-svn: 144881
2011-11-17 03:44:24 +00:00
Francois Pichet 78286b24fd In Microsoft mode, make "Unqualified lookup into dependent bases of class templates" works inside static functions.
llvm-svn: 144729
2011-11-15 23:33:34 +00:00
Douglas Gregor 0201a4c2d3 When we're checking access in a dependent context, don't try to look
at the bases of an undefined class. Fixes <rdar://problem/10438657>.

llvm-svn: 144582
2011-11-14 23:00:43 +00:00
Francois Pichet f707ae6733 Move "Unqualified lookup into dependent bases of class templates" Microsoft specific behavior from -fms-extensions to -fms-compatibility.
llvm-svn: 144341
2011-11-11 00:12:11 +00:00
Douglas Gregor 6ea1d665a7 Mark the overloaded atomic builtins as having custom type checking,
which they do. This avoids all of the default argument promotions that
we (1) don't want, and (2) undo during that custom type checking, and
makes sure that we don't run into trouble during template
instantiation. Fixes PR11320.

llvm-svn: 144110
2011-11-08 19:45:38 +00:00
Douglas Gregor 4109afa1f1 Drastically simplify the mapping from the declaration corresponding to
the injected-class-name of a class (or class template) to the
declaration that results from substituting the given template
arguments. Previously, we would actually perform a substitution into
the injected-class-name type and then retrieve the resulting
declaration. However, in certain, rare circumstances involving
deeply-nested member templates, we would get the wrong substitution
arguments.

This new approach just matches up the declaration with a declaration
that's part of the current context (or one of its parents), which will
either be an instantiation (during template instantiation) or the
declaration itself (during the definition of the template). This is
both more efficient (we're avoiding a substitution) and more correct
(we can't get the template arguments wrong in the member-template
case). 

Fixes <rdar://problem/9676205>.

Reinstated, now that we have the fix in r143967.

llvm-svn: 143968
2011-11-07 17:43:18 +00:00
Douglas Gregor df593fbeda Tighten up the conditions under which we consider ourselves to be
entering the context of a nested-name-specifier. Fixes
<rdar://problem/10397846>.

llvm-svn: 143967
2011-11-07 17:33:42 +00:00
Devang Patel 2ccf84e3a5 Revert r143551. It is causing g++.dg/template/crash52.C test failure.
llvm-svn: 143725
2011-11-04 18:52:43 +00:00
Douglas Gregor 8f5653a999 Drastically simplify the mapping from the declaration corresponding to
the injected-class-name of a class (or class template) to the
declaration that results from substituting the given template
arguments. Previously, we would actually perform a substitution into
the injected-class-name type and then retrieve the resulting
declaration. However, in certain, rare circumstances involving
deeply-nested member templates, we would get the wrong substitution
arguments.

This new approach just matches up the declaration with a declaration
that's part of the current context (or one of its parents), which will
either be an instantiation (during template instantiation) or the
declaration itself (during the definition of the template). This is
both more efficient (we're avoiding a substitution) and more correct
(we can't get the template arguments wrong in the member-template
case). 

Fixes <rdar://problem/9676205>.

llvm-svn: 143551
2011-11-02 17:38:53 +00:00
Douglas Gregor fe0055e6c8 When we see an out-of-line definition of a member class template that
does not match any declaration in the class (or class template), be
sure to mark it as invalid. Fixes PR10924 / <rdar://problem/10119422>.

llvm-svn: 143504
2011-11-01 21:35:16 +00:00
Douglas Gregor d73f3ddb44 Rework the AST for the initializer of a delegating constructor, so
that it retains source location information for the type. Aside from
general goodness (being able to walk the types described in that
information), we now have a proper representation for dependent
delegating constructors. Fixes PR10457 (for real).

llvm-svn: 143410
2011-11-01 01:16:03 +00:00
Richard Smith ae1bab56d9 Fix crash due to missing array-to-pointer decay when instantiating an unresolved
member expression. Refactoring to follow.

llvm-svn: 143017
2011-10-26 06:49:26 +00:00
Douglas Gregor 4a2a8f7fb8 Check for unexpanded parameter packs in the name that guards a
Microsoft __if_exists/__if_not_exists statement. Also note that we
weren't traversing DeclarationNameInfo *at all* within the
RecursiveASTVisitor, which would be rather fatal for variadic
templates.

llvm-svn: 142906
2011-10-25 03:44:56 +00:00
Douglas Gregor deb4a2be67 Implement support for dependent Microsoft __if_exists/__if_not_exists
statements. As noted in the documentation for the AST node, the
semantics of __if_exists/__if_not_exists are somewhat different from
the way Visual C++ implements them, because our parsed-template
representation can't accommodate VC++ semantics without serious
contortions. Hopefully this implementation is "good enough".

llvm-svn: 142901
2011-10-25 01:33:02 +00:00
Douglas Gregor 43edb32f1f Rework Microsoft __if_exists/__if_not_exists parsing and semantic
analysis to separate dependent names from non-dependent names. For
dependent names, we'll behave differently from Visual C++:

  - For __if_exists/__if_not_exists at class scope, we'll just warn
    and then ignore them.
  - For __if_exists/__if_not_exists in statements, we'll treat the
    inner statement as a compound statement, which we only instantiate
    in templates where the dependent name (after instantiation)
    exists. This behavior is different from VC++, but it's as close as
    we can get without encroaching ridiculousness.

The latter part (dependent statements) is not yet implemented.

llvm-svn: 142864
2011-10-24 22:31:10 +00:00
Douglas Gregor fbf8752597 When performing name lookup for the previous declaration of a field,
be sure to consider all of the possible lookup results. We were
assert()'ing (but behaving correctly) for unresolved values. Fixes
PR11134 / <rdar://problem/10290422>.

llvm-svn: 142652
2011-10-21 15:47:52 +00:00
Douglas Gregor 44e5a0a72b Diagnose class template (partial) specializations that occur in the
*wrong* class scope. This is one of the problems behind
<rdar://problem/9676205>.

llvm-svn: 142588
2011-10-20 16:41:18 +00:00
Douglas Gregor f65d8ffca7 When we parse something that looks like a templated friend tag but
actually just has an extraneous 'template<>' header, strip off the
'template<>' header and treat it as a normal friend tag. Fixes PR10660
/ <rdar://problem/9958322>.

llvm-svn: 142587
2011-10-20 15:58:54 +00:00
David Blaikie cc5f8f0d9e Switch to the C++11 warning flags in tests.
Patch by Ahmed Charles!

llvm-svn: 142340
2011-10-18 05:54:07 +00:00
Douglas Gregor f333f8c40d When transforming the arguments for a C++ "new" expression, make sure
to drop the implicitly-generated value initialization expression used
for initializing scalars. Fixes <rdar://problem/10283928>.

llvm-svn: 142330
2011-10-18 02:43:19 +00:00
Richard Smith 050d261ec7 Refactor the checking for explicit template instantiations being performed in
the right namespace in C++11 mode. Teach the code to prefer the 'must be in
precisely this namespace' diagnostic whenever that's true, and fix a defect
which resulted in the -Wc++11-compat warning in C++98 mode sometimes being
omitted.

llvm-svn: 142329
2011-10-18 02:28:33 +00:00
Douglas Gregor 041b084f73 When declaring an out-of-line template, attempt to rebuild any types
within the template parameter list that may have changed now that we
know the current instantiation. Fixes <rdar://problem/10194295>.

llvm-svn: 141954
2011-10-14 15:31:12 +00:00
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Douglas Gregor ebcfbb5d22 When we determine that a function template specialization produced as
part of template argument deduction is ill-formed, we mark it as
invalid and treat it as a deduction failure. If we happen to find that
specialization again, treat it as a deduction failure rather than
silently building a call to the declaration.

Fixes PR11117, a marvelous bug where deduction failed after creating
an invalid specialization, causing overload resolution to pick a
different candidate. Then we performed a similar overload resolution
later, and happily picked the invalid specialization to
call... resulting in a silent link failure.

llvm-svn: 141809
2011-10-12 20:35:48 +00:00
Douglas Gregor 205d044552 Switch diagnostic text from "C++0x" over to "C++11".
We'd also like for "C++11" or "c++11" to be used for the warning
groups, but without removing the old warning flags. Patches welcome;
I've run out of time to work on this today.

llvm-svn: 141801
2011-10-12 19:26:40 +00:00
John McCall 50a2c2c19d Catch placeholder types in DefaultLvalueConversion
and DefaultFunctionArrayLvalueConversion.  To prevent
significant regression for should-this-be-a-call fixits,
and to repair some such regression from the introduction of
bound member placeholders, make those placeholder checks
try to build calls appropriately.  Harden the build-a-call
logic while we're at it.

llvm-svn: 141738
2011-10-11 23:14:30 +00:00
Douglas Gregor f892c7fe60 For the various CF and NS attributes, don't complain if the parameter
or return types are dependent. Fixes PR9049.

llvm-svn: 141518
2011-10-09 22:26:49 +00:00
Richard Smith 256336d9ab Mark the ExtWarn for in-class initialization of static const float members as a GNU extension. Don't extend the scope of this extension to all literal types in C++0x mode.
llvm-svn: 140820
2011-09-29 23:18:34 +00:00
Richard Smith 2316cd8b79 constexpr: semantic checking for constexpr variables.
We had an extension which allowed const static class members of floating-point type to have in-class initializers, 'as a C++0x extension'. However, C++0x does not allow this. The extension has been kept, and extended to all literal types in C++0x mode (with a fixit to add the 'constexpr' specifier).

llvm-svn: 140801
2011-09-29 19:11:37 +00:00
Douglas Gregor 882a61a640 Diagnose attempts to use 'using typename' with a non-identifier name,
from Stepan Dyatkovskiy. Fixes PR10925.

llvm-svn: 140528
2011-09-26 14:30:28 +00:00
Douglas Gregor 5223529b27 Don't finalize checking of base and member initializers for a
constructor template. Fixes PR10457.

llvm-svn: 140350
2011-09-22 23:04:35 +00:00
Douglas Gregor 7c26c04ba9 Diagnose attempts to write a templated data member, from Stepan
Dyatkovskiy! Fixes PR10896.

llvm-svn: 140250
2011-09-21 14:40:46 +00:00
Eli Friedman 8eac6c2187 PR10864: make sure we correctly delay type-checking for inline asm tied operands with dependent type. Patch by Likai Liu.
llvm-svn: 139716
2011-09-14 19:20:00 +00:00
Douglas Gregor 6b3bcf29f5 When type-checking a call to an overloaded, builtin atomic operation,
construct a new DeclRefExpr rather than re-using the existing
DeclRefExpr. Patch by Likai Liu, fixes PR8345.

llvm-svn: 139373
2011-09-09 16:51:10 +00:00
Francois Pichet bcf6471010 In Microsoft mode, if we are inside a template class member function and we can't resolve a function call then create a type-dependent CallExpr even if the function has no type dependent arguments. The goal is to postpone name lookup to instantiation time to be able to search into type dependent base classes.
With this patch in, clang will generate only 37 errors (down from 212) when parsing a typical MFC source file.

llvm-svn: 139210
2011-09-07 00:14:57 +00:00
Eli Friedman 755c0c996a Don't assert on taking the address of a non-type template parameter. Fixes PR10766.
llvm-svn: 138648
2011-08-26 20:28:17 +00:00
Matt Beaumont-Gay 045bde420b Fix a crash-on-invalid.
Much to everyone's surprise, the default constructor for TypeResult produces
an instance with Invalid == false. This seems like a decision we may want to
revisit.

llvm-svn: 138601
2011-08-25 23:22:24 +00:00
Chandler Carruth 463394752b Whitelist operator== and operator!= as valid for unused value warnings,
even when overloaded and user-defined. These operators are both more
valuable to warn on (due to likely typos) and extremely unlikely to be
reasonable for use to trigger side-effects.

llvm-svn: 137823
2011-08-17 09:49:44 +00:00
Chandler Carruth e2669397f1 Treating the unused equality comparisons as something other than part of
-Wunused was a mistake. It resulted in duplicate warnings and lots of
other hacks. Instead, this should be a special sub-category to
-Wunused-value, much like -Wunused-result is.

Moved to -Wunused-comparison, moved the implementation to piggy back on
the -Wunused-value implementation instead of rolling its own, different
mechanism for catching all of the "interesting" statements.

I like the unused-value mechanism for this better, but its currently
missing several top-level statements. For now, I've FIXME-ed out those
test cases. I'll enhance the generic infrastructure to catch these
statements in a subsequent patch.

This patch also removes the cast-to-void fixit hint. This hint isn't
available on any of the other -Wunused-value diagnostics, and if we want
it to be, we should add it generically rather than in one specific case.

llvm-svn: 137822
2011-08-17 09:34:37 +00:00
Francois Pichet 127bea8f48 fix typo in test.
llvm-svn: 137592
2011-08-14 22:30:29 +00:00
Francois Pichet 00c7e6ceb1 Implement function template specialization at class scope extension in Microsoft mode. A new AST node is introduced: ClassScopeFunctionSpecialization. This node holds a FunctionDecl that is not yet specialized; then during the class template instantiation the ClassScopeFunctionSpecialization will spawn the actual function specialization.
Example:
template <class T>
class A {
public:
  template <class U> void f(U p) {  }
  template <> void f(int p) {  } // <== class scope specialization
};

This extension is necessary to parse MSVC standard C++ headers, MFC and ATL code.
BTW, with this feature in, clang can parse (-fsyntax-only) all the MSVC 2010 standard header files without any error.

llvm-svn: 137573
2011-08-14 03:52:19 +00:00