Commit Graph

934 Commits

Author SHA1 Message Date
John McCall 29ac8e2ecd For internal consistency's sake, compute the value kind of a dependent cast
based on the known properties of the casted-to type.  Fixes a crash on spirit.

llvm-svn: 120180
2010-11-26 10:57:22 +00:00
Douglas Gregor 72ebdabc5d When we're type-checking the result of calling a conversion function
(while computing user conversion sequences), make sure that a result
of class type is a complete class type. Had we gone through
ActOnCallExpr, this would have happened when we built the CallExpr.

Fixes PR8425.

llvm-svn: 119005
2010-11-13 19:36:57 +00:00
Chandler Carruth 456daba135 Switch to using %clang_cc1 properly rather than manually passing the -cc1 flag.
llvm-svn: 118996
2010-11-13 10:19:35 +00:00
John McCall 31f82720d0 Replace one hack with a different hack: strip out the ObjectType
parameters to the Transform*Type functions and instead call out
the specific cases where an object type and the unqualified lookup
results are important.  Fixes an assert and failed compile on
a testcase from PR7248.

llvm-svn: 118887
2010-11-12 08:19:04 +00:00
Douglas Gregor 869853eea1 Instantiate class member template partial specialization declarations
in the order they occur within the class template, delaying
out-of-line member template partial specializations until after the
class has been fully instantiated. This fixes a regression introduced
by r118454 (itself a fix for PR8001).

llvm-svn: 118704
2010-11-10 19:44:59 +00:00
Nick Lewycky 6147891648 Don't lose track of previous-declarations when instantiating a class template.
Fixes PR8001.

llvm-svn: 118454
2010-11-08 23:29:42 +00:00
Douglas Gregor bd6b17f4ef Improve our handling of C++ [class.copy]p3, which specifies that a
constructor template will not be used to copy a class object to a
value of its own type. We were eliminating all constructor templates
whose specializations look like a copy constructor, which eliminated
important candidates. Fixes PR8182.

llvm-svn: 118418
2010-11-08 17:16:59 +00:00
Douglas Gregor 1ccc8416a0 Remove broken support for variadic templates, along with the various
abstractions (e.g., TemplateArgumentListBuilder) that were designed to
support variadic templates. Only a few remnants of variadic templates
remain, in the parser (parsing template type parameter packs), AST
(template type parameter pack bits and TemplateArgument::Pack), and
Sema; these are expected to be used in a future implementation of
variadic templates.

But don't get too excited about that happening now.

llvm-svn: 118385
2010-11-07 23:05:16 +00:00
Douglas Gregor 25edf4302f When searching for an instantiated declaration requires instantiation
of its parent context, be sure to update the parent-context pointer
after instantiation. Fixes two anonymous-union instantiation issues in
<rdar://problem/8635664>.

llvm-svn: 118313
2010-11-05 23:22:45 +00:00
Douglas Gregor 3ade5704fe When canonicalizing nested-name-specifiers involving dependent names
or dependent specializations, rip apart the dependent name/dependent
specialization to recanonicalize its pieces, because
nested-name-specifiers store "dependent-type::identifier" differently
than types do. Fixes PR7419.

llvm-svn: 118211
2010-11-04 00:09:33 +00:00
Nick Lewycky b9b3927356 Preserve the template type parameter name when instantiating a templace.
Fixes PR8489.

llvm-svn: 117776
2010-10-30 06:48:20 +00:00
Douglas Gregor bde20c0342 When we perform name lookup for a template, we may end up finding an
ambiguous name where none of the declarations found are actually
templates. In this case, make sure we clear out the ambiguous-path
data when recomputing the lookup result kind. Fixes PR8439.

llvm-svn: 117112
2010-10-22 17:36:51 +00:00
John McCall 32723e9198 Tag references shouldn't ever get template parameter lists.
Fixes rdar://problem/8568507

llvm-svn: 116843
2010-10-19 18:40:57 +00:00
Douglas Gregor f0873f4c85 When marking declarations referenced within an expression (e.g.,
within a default argument), recurse into default arguments. Fixes
PR8401, a regression I introduced in r113700 while refactoring our
handling of "used" declarations in default arguments.

llvm-svn: 116817
2010-10-19 17:17:35 +00:00
Douglas Gregor d07ba34a44 There is no reason for dereferencing a pointer-to-member to require
that the class type into which the pointer points be complete, even
though the standard requires it. GCC/EDG do not require a complete
type here, so we're calling this a problem with the standard. Fixes
PR8328.

llvm-svn: 116429
2010-10-13 20:41:14 +00:00
Douglas Gregor dc13b04a98 Place conversion warnings for non-type template arguments under the
control of -Wconversion, and ignore them by default.

llvm-svn: 116415
2010-10-13 18:27:55 +00:00
Douglas Gregor b39215942e Fix a silly bug in the suppression of non-error diagnostics in a
SFINAE context, where we weren't getting the right diagnostic argument
count. I blame DiagnosticBuilder's weirdness. Fixes PR8372.

llvm-svn: 116411
2010-10-13 17:22:14 +00:00
John McCall 036855a0ed Enter the context of the declared function template when performing
deduction and the final substitution, but not while substituting the
explicit template arguments.  Fixes rdar://problem/8537391

llvm-svn: 116332
2010-10-12 19:40:14 +00:00
Douglas Gregor 0bf3140424 Implement C++0x scoped enumerations, from Daniel Wallin! (and tweaked a
bit by me). 

llvm-svn: 116122
2010-10-08 23:50:27 +00:00
Douglas Gregor ac2e43082a Fix handling of dependent nested namespace specifiers in UsingDecls
during template instantiation, from Martin Vejnar!

llvm-svn: 115051
2010-09-29 17:58:28 +00:00
Douglas Gregor 29d907de03 When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement. 

The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given

  x = p->y

if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.

llvm-svn: 114225
2010-09-17 22:25:06 +00:00
Douglas Gregor 6ed2feebfc When marking the declarations in a default argument expression as
"used", at the time that the default argument itself is used, also
mark destructors that will be called by this expression. This fixes a
regression that I introduced in r113700, which broke WebKit, and fixes
<rdar://problem/8427926>.

llvm-svn: 113883
2010-09-14 22:55:20 +00:00
Abramo Bagnara 6a0c4097f1 Parentheses around address non-type template argument is demoted to an extension warning.
llvm-svn: 113739
2010-09-13 06:06:58 +00:00
Douglas Gregor 8ce63154d0 When diagnosing C++ [temp.expl.spec]p3 in C++98/03 mode, downgrade the
error to a warning if we're in a case that would be allowed in
C++0x. This "fixes" PR8084 by making Clang accept more code than GCC
and (non-strict) EDG do. 

Also, add the missing test case for the C++0x semantics, which should
have been in r113717.

llvm-svn: 113718
2010-09-12 05:24:55 +00:00
Douglas Gregor 32b3de519d Teach the EvaluatedExprVisitor and its client, which marks
declarations in potentially-evaluated subexpressions, about
recursion. Fixes the release-mode self-host failure I introduced in
r113700.

llvm-svn: 113708
2010-09-11 23:32:50 +00:00
Douglas Gregor 8a01b2a392 When parsing default function arguments, do not mark any declarations
used in the default function argument as "used". Instead, when we
actually use the default argument, make another pass over the
expression to mark any used declarations as "used" at that point. This
addresses two kinds of related problems:

  1) We were marking some declarations "used" that shouldn't be,
  because we were marking them too eagerly.
  2) We were failing to mark some declarations as "used" when we
  should, if the first time it was instantiated happened to be an
  unevaluated context, we wouldn't mark them again at a later point.

I've also added a potentially-handy visitor class template
EvaluatedExprVisitor, which only visits the potentially-evaluated
subexpressions of an expression. I bet this would have been useful for
noexcept...

Fixes PR5810 and PR8127.

llvm-svn: 113700
2010-09-11 20:24:53 +00:00
Douglas Gregor ce3449f5bd Tweak GetPreamblePCHPath() to more closely match the behavior of the
Windows GetTempPath() function, and be sure to create the directory in
which the precompiled preamble will reside before creating the
temporary file itself.

llvm-svn: 113695
2010-09-11 17:51:16 +00:00
John McCall db76892e72 Support in-class initialization of static const floating-point data members.
llvm-svn: 113663
2010-09-10 23:21:22 +00:00
Chris Lattner 7f2c7f4ef3 "const std::vector<int>*" not "std::vector<int> const*"
llvm-svn: 113094
2010-09-05 00:27:00 +00:00
Chris Lattner 24b89469ac 'const std::type_info*' instead of 'std::type_info const*'
llvm-svn: 113092
2010-09-05 00:17:29 +00:00
Chris Lattner 53fa04909c make clang print types as "const int *" instead of "int const*",
which is should have done from the beginning.  As usual, the most
fun with this sort of change is updating all the testcases.

llvm-svn: 113090
2010-09-05 00:04:01 +00:00
Chandler Carruth f92bd8cf22 Fix PR7402 when it strikes via template instantiation.
llvm-svn: 113019
2010-09-03 21:54:20 +00:00
Chandler Carruth 9bb67f4d1a Allow anonymous and local types. The support was already in place for these,
but this makes them work even as an extension in C++98. This resolves PR8077.

llvm-svn: 113011
2010-09-03 21:12:34 +00:00
Douglas Gregor a477e2afe7 When template substitution into a template parameter reduces the level
of that parameter, reduce the level by the number of active template
argument lists rather than by 1. The number of active template
argument lists is only > 1 when we have a class template partial
specialization of a member template of a class template that itself is
a member template of another class template. 

... and Boost.MSM does this. Fixes PR7669.

llvm-svn: 112551
2010-08-30 23:23:59 +00:00
Gabor Greif 3fe617cc09 add two more use-cases (explicit instantiation) that should pass now
llvm-svn: 112533
2010-08-30 21:45:06 +00:00
Gabor Greif 718d515b3a fix dual aspect of PR8007,
namely when the friend function prototype is already used
at the point of the template definition that is supposed
to inject the friend function. Testcase verifies four
scenarios.
I would like receive some code review for this.

llvm-svn: 112524
2010-08-30 21:10:05 +00:00
Douglas Gregor 1262b0636e Fix an corner-case assertion introduced by the refactoring in r112258;
when we're taking the address of a unresolvable value, it might be an
implicit member access. Fixes some Boost.Spirit regressions.

llvm-svn: 112487
2010-08-30 16:00:47 +00:00
John McCall 0856906b1e When perform exact-qualifier-match template argument deduction,
properly account for the possibility that certain opaque types
might be more qualified than they appear.  Fixes PR7708.

llvm-svn: 112390
2010-08-28 22:14:41 +00:00
John McCall fb3f9ba969 If filtering a lookup result leaves it ambiguous, keep the ambiguity
kind.  Fixes PR7252.

llvm-svn: 112383
2010-08-28 20:17:00 +00:00
Gabor Greif b0c557be1e add another test for PR8007
this is still failing, need to come up with a fix
(but we are in good company as the first gcc version
 pass this test will be v4.6)

llvm-svn: 112369
2010-08-28 12:12:45 +00:00
Gabor Greif 468aa3b20c check whether sema issues a redefinition error
llvm-svn: 112347
2010-08-28 02:00:22 +00:00
Gabor Greif 73ddbc51ab note to self: save before committing; add PR
llvm-svn: 112339
2010-08-28 00:48:36 +00:00
Gabor Greif 1d28820888 fix test by applying it in top namespace: PR8007 only showed up this way
llvm-svn: 112338
2010-08-28 00:45:56 +00:00
Gabor Greif b6aba3ef28 fix PR8007
reordering and redefinition issues still may linger,
I plan to nail them next

llvm-svn: 112333
2010-08-28 00:16:06 +00:00
Gabor Greif a56984c72f reproduction recipe for PR8007, expected to fail for now, review welcome
llvm-svn: 112326
2010-08-27 23:39:49 +00:00
John McCall 1ababa63de Continue to instantiate sub-statements in a CompoundStmt as long as
we don't see a DeclStmt (failure to instantiate which generally causes
panic).

llvm-svn: 112282
2010-08-27 19:56:05 +00:00
Nick Lewycky fe71238b8d Add a workaround for PR7947, a crash trying to recover from invalid C++ code.
llvm-svn: 111675
2010-08-20 20:54:15 +00:00
John McCall 13d031593e Correctly instantiate templates with non-type template arguments that
are local externs.  Fixes <rdar://problem/8302138>.

llvm-svn: 111570
2010-08-19 23:06:02 +00:00
John McCall f733268e7a When deducing the element type of an array, ignore qualifiers if
the context allows us to ignore qualifiers on the array type itself.

llvm-svn: 111486
2010-08-19 00:20:19 +00:00
John McCall 815039af77 Implicit decl ref expressions might not have name locations; don't silently
fail to instantiate them.

llvm-svn: 111293
2010-08-17 21:27:17 +00:00
Eli Friedman 964dbda0e9 PR7837: For qualified id's, make sure the decl context is complete if not
dependent in ActOnIdExpression.  (This issue only shows up with member
operators because an operator is never a type.)

llvm-svn: 110486
2010-08-06 23:41:47 +00:00
Douglas Gregor 229c281d37 Remove some incorrect assertions when deduction template arguments in
a template-argument-list. When template template parameters are
involved, we won't already have checked the template-argument-list (it
may not be known yet!). Fixes PR7807.

llvm-svn: 110444
2010-08-06 14:15:26 +00:00
John McCall 42d7d19710 TDK_InconsistentQuals is really totally different from TDK_Inconsistent.
Rename it to TDK_Underqualified to avoid this sort of confusion and give it
its own diagnostic.

llvm-svn: 110318
2010-08-05 09:05:08 +00:00
John McCall 6602bb1115 Instantiate attributes from the pattern record when instantiating
a class template.  Fixes rdar://problem/8243419.

llvm-svn: 109967
2010-08-01 02:01:53 +00:00
John McCall 413021a8c7 Improve error recovery when presented with an ill-formed template-id
(e.g. due to a broken template argument) following template parameters.

Fixes rdar://problem/8254267

llvm-svn: 109853
2010-07-30 06:26:29 +00:00
Douglas Gregor 43397fc4dc Don't set out-of-line template specialization/definition information
for AST nodes that aren't actually out-of-line (i.e., require a
nested-name-specifier). Fixes <rdar://problem/8204126>.

llvm-svn: 109704
2010-07-28 23:59:57 +00:00
Douglas Gregor bbfd2c0a86 Enable expression transformations in the current-instantiation
rebuilder, i.e., remove a silly short-sighted hack from long
ago. Thanks to Abramo Bagnara for the test case/bug report!

llvm-svn: 109583
2010-07-28 15:14:14 +00:00
Douglas Gregor df65c8ed2a When a nested-name-specifier refers into a current instantiation that has
dependent bases, construct a dependent nested-name-specifier rather
than complaining that the name could not be found within the current
instantiation itself. Fixes PR7725.

llvm-svn: 109582
2010-07-28 14:49:07 +00:00
Eli Friedman 6b197e0651 PR7724: Don't try to evaluate value-dependent expressions.
llvm-svn: 109532
2010-07-27 19:14:53 +00:00
Eli Friedman 9255adfb7a PR7698: Make sure we correctly handle the initialization of an array with
dependent size.

llvm-svn: 109356
2010-07-24 21:19:15 +00:00
Douglas Gregor fc6c3e73cd When performing template name lookup for a dependent member access
expression such as the "foo" in "this->blah.foo<1, 2>", and we can't
look into the type of "this->blah" (e.g., because it is dependent),
look into the local scope of a template of the same name. Fixes
<rdar://problem/8198511>.

llvm-svn: 108531
2010-07-16 16:54:17 +00:00
Douglas Gregor 5f0e252f63 When there are extra or missing template parameter lists in a template
definition, we're likely going to end up breaking the invariants of
the template system, e.g., that the depths of template parameter lists
match up with the nesting template of the template. So, make sure we
mark such ill-formed declarations as invalid or don't even build them
at all.

llvm-svn: 108372
2010-07-14 23:14:12 +00:00
Chandler Carruth cb3b5a483f Wire up '-Wignored-qualifiers' to the warning on 'const' in 'const int f()'.
This flag and warning match GCC semantics. Also, move it to -Wextra as this is
a largely cosmetic issue and doesn't seem to mask problems. Subsequent fixes to
the tests which no longer by default emit the warning. Added explicit test
cases for both C and C++ behavior with the warning turned on.

llvm-svn: 108325
2010-07-14 06:36:18 +00:00
Douglas Gregor f5b160f89c When computing the canonical profile of a DeclRefExpr or MemberExpr,
don't include the nested-name-specifier or template arguments: they
were only relevant when resolving the declaration. Fixes PR7460.

llvm-svn: 108235
2010-07-13 08:37:11 +00:00
Douglas Gregor 603d81bf8d When forming a function call or message send expression, be sure to
strip cv-qualifiers from the expression's type when the language calls
for it: in C, that's all the time, while C++ only does it for
non-class types. 

Centralized the computation of the call expression type in
QualType::getCallResultType() and some helper functions in other nodes
(FunctionDecl, ObjCMethodDecl, FunctionType), and updated all relevant
callers of getResultType() to getCallResultType().

Fixes PR7598 and PR7463, along with a bunch of getResultType() call
sites that weren't stripping references off the result type (nothing
stripped cv-qualifiers properly before this change).

llvm-svn: 108234
2010-07-13 08:18:22 +00:00
Douglas Gregor 6cc1df5d3d Provide a special diagnostic for attempts to explicitly specialize
class templates within class scope (which is ill-formed), and recover
by dropping the explicit specialization entirely. Fixes the infinite
loop in PR7622.

llvm-svn: 108217
2010-07-13 00:10:04 +00:00
Chris Lattner 33919e7450 fix PR7280 by making the warning on code like this:
int test1() {
  return;
}

default to an error.

llvm-svn: 108108
2010-07-11 23:34:02 +00:00
Chandler Carruth 17773fcd83 Lay the ground work for resoving PR7047. This doesn't actually fix it because
default arguments to template parameters don't have a DeclContext when
instantiated, and so we can't detect that we're in an instantiation context as
opposed to the definition context. However, it fixes the more commonly-occuring
cases in TMP code that use devolve to this type of tautology after
substitution.

llvm-svn: 108044
2010-07-10 12:30:03 +00:00
Douglas Gregor 9961ce9428 When performing substitution of template arguments within the body of
a template, be sure to include the template arguments from the
injected-class-name. Fixes PR7587.

llvm-svn: 107895
2010-07-08 18:37:38 +00:00
Douglas Gregor bc0c79b4ab Clean up the diagnostic complaining about the element type of a vector
type so that it actually complains about the element type itself.

llvm-svn: 107299
2010-06-30 17:30:41 +00:00
Daniel Dunbar 8452ef0798 tests: Use %clangxx when using driver for C++, in case C++ support is disabled.
llvm-svn: 107153
2010-06-29 16:52:24 +00:00
Chandler Carruth f40c42f2cd Implement dependent alignment attribute support. This is a bit gross given the
current attribute system, but it is enough to handle class templates which
specify parts of their alignment in terms of their template parameters.

This also replaces the attributes test in SemaTemplate with one that actually
tests working attributes instead of broken ones. I plan to add more tests here
for non-dependent attributes in a subsequent patch.

Thanks to John for walking me through some of this. =D

llvm-svn: 106818
2010-06-25 03:22:07 +00:00
Douglas Gregor ef4a2a2b54 Apply array-to-pointer decay when instantiating a MemberExpr. Fixes
PR7405, patch by Kyle Lippincott!

llvm-svn: 106523
2010-06-22 02:41:05 +00:00
Douglas Gregor ebada077d9 Given Decl::isUsed() a flag indicating when to consider the "used"
attribute as part of the calculation. Sema::MarkDeclReferenced(), and
a few other places, want only to consider the "used" bit to determine,
e.g, whether to perform template instantiation. Fixes a linkage issue
with Boost.Serialization.

llvm-svn: 106252
2010-06-17 23:14:26 +00:00
Douglas Gregor ffa20398a6 When pushing a copy of the TypeLoc information for a dependent
template specialization type, copy the location information but use
the new type. Fixes PR7385.

llvm-svn: 106224
2010-06-17 16:03:49 +00:00
Douglas Gregor bb1196534c When we see a 'template' disambiguator that marks the next identifier
(or operator-function-id) as a template, but the context is actually
non-dependent or the current instantiation, allow us to use knowledge
of what kind of template it is, e.g., type template vs. function
template, for further syntactic disambiguation. This allows us to
parse properly in the presence of stray "template" keywords, which is
necessary in C++0x and it's good recovery in C++98/03.

llvm-svn: 106167
2010-06-16 23:00:59 +00:00
Douglas Gregor f7d7771812 Fix the recently-added warning about 'typename' and 'template'
disambiguation keywords outside of templates in C++98/03. Previously,
the warning would fire when the associated nested-name-specifier was
not dependent, but that was a misreading of the C++98/03 standard:
now, we complain only when we're outside of any template.

llvm-svn: 106161
2010-06-16 22:31:08 +00:00
Douglas Gregor 7dbfb46163 Canonicalize template template parameters when canonicalizing a
template name that refers to such a parameter. It's amazing that this
problem didn't surface earlier. Fixes PR7387.

llvm-svn: 106147
2010-06-16 21:09:37 +00:00
Douglas Gregor 94584683fa Don't poke at an undefined class type of a field. Fixes PR7355.
llvm-svn: 106111
2010-06-16 16:54:04 +00:00
Douglas Gregor 1c69bf00ae If a non-dependent base class initializer fails to match any direct or
virtual base class, but the class still has dependent base classes,
then don't diagnose the failed match as an error: the right base class
might magically appear. Fixes PR7259.

llvm-svn: 106103
2010-06-16 16:03:14 +00:00
Douglas Gregor c9d2682df3 Warn when a 'typename' or a 'template' keyword refers to a
non-dependent type or template name, respectively, in C++98/03. Fixes
PR7111 and <rdar://problem/8002682>.

llvm-svn: 105968
2010-06-14 22:07:54 +00:00
John McCall dad856dba3 Provide an Objective C mangling for wchar_t. Patch by Nico Weber!
llvm-svn: 105818
2010-06-11 10:11:05 +00:00
Douglas Gregor 205a361413 When we've parsed a nested-name-specifier in a member access
expression, "forget" about the object type; only the
nested-name-specifier matters for name lookup purposes. Fixes PR7239.

llvm-svn: 104834
2010-05-27 15:25:59 +00:00
John McCall bf8c519a0d Require a complete type when performing the qualified lookup during
instantiation of a dependent elaborated type specifier.  Fixes PR 7199.

llvm-svn: 104822
2010-05-27 06:40:31 +00:00
Douglas Gregor 1b30b3c9fa When transforming a C++ "new" expression's constructor arguments, drop
any arguments that are default-argument expressions. The can show up
when we have a new expression whose constructor arguments are not
type-dependent and whose allocated type is not dependent and has a
constructor with default arguments. Fixes PR7202.

llvm-svn: 104690
2010-05-26 07:10:06 +00:00
Douglas Gregor e05d3cb770 A type- or value-dependent expression cannot use bitfield
promotion. Fixes <rdar://problem/8020920>.

llvm-svn: 104545
2010-05-24 20:13:53 +00:00
Douglas Gregor 024d80e571 Don't look for a destructor in a dependent type. Fixes PR7198.
llvm-svn: 104445
2010-05-22 17:12:29 +00:00
Douglas Gregor 959d5a0cbd Implement support for variable length arrays in C++. VLAs are limited
in several important ways:

  - VLAs of non-POD types are not permitted.
  - VLAs cannot be used in conjunction with C++ templates.

These restrictions are intended to keep VLAs out of the parts of the
C++ type system where they cause the most trouble. Fixes PR5678 and
<rdar://problem/8013618>.

llvm-svn: 104443
2010-05-22 16:17:30 +00:00
Douglas Gregor 20c38a7c58 Improve recovery when we see a dependent template name that is missing
the required "template" keyword, using the same heuristics we do for
dependent template names in member access expressions, e.g.,

test/SemaTemplate/dependent-template-recover.cpp:11:8: error: use 'template'
      keyword to treat 'getAs' as a dependent template name
    T::getAs<U>();
       ^
       template 

Fixes PR5404.

llvm-svn: 104409
2010-05-21 23:43:39 +00:00
Douglas Gregor 786123dc48 Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g., 

  t->getAs<T>()

where getAs is a member of an unknown specialization. C++ requires
that we treat "getAs" as a value, but that would fail to parse since T
is the name of a type. We would then fail at the '>', since a type
cannot be followed by a '>'.

This is a very common error for C++ programmers to make, especially
since GCC occasionally allows it when it shouldn't (as does Visual
C++). So, when we are in this case, we use tentative parsing to see if
the tokens starting at "<" can only be parsed as a template argument
list. If so, we produce a diagnostic with a fix-it that states that
the 'template' keyword is needed:

test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword
      is required to treat 'getAs' as a dependent template name
    t->getAs<T>();
       ^
       template 

This is just a start of this patch; I'd like to apply the same
approach to everywhere that a template-id with dependent template name
can be parsed.

llvm-svn: 104406
2010-05-21 23:18:07 +00:00
Douglas Gregor 9f44d1453b When instantiating a function declaration within a function template,
be sure to merge its parameter scope with its parent's scope. Fixes
PR7184.

llvm-svn: 104386
2010-05-21 21:25:08 +00:00
Douglas Gregor 04163186a7 When instantiating anonymous structs/unions within a function, make
sure that the anonymous struct/union record declaration gets
instantiated before the variable declaration, and that it and its
fields (recursively) get entries in the local instantiation map. Fixes
PR7088.

llvm-svn: 104305
2010-05-21 00:31:19 +00:00
Douglas Gregor 6044d691bb Revert r104106; it's breaking linking of Boost.Serialization.
llvm-svn: 104121
2010-05-19 17:02:24 +00:00
Douglas Gregor e9ceb31405 Profile type-dependent uses of overloaded operators in C++ the same
way regardless of whether some overloaded operator functions were
found by name lookup within the template. Fixes PR6851.

llvm-svn: 104107
2010-05-19 04:13:23 +00:00
Douglas Gregor 21553f5970 Teach clang to instantiate attributes on more declarations. Fixes PR7102.
llvm-svn: 104106
2010-05-19 03:39:53 +00:00
Douglas Gregor bdb604a806 Protect isIntegerConstantExpr from seeing type- or value-dependent
expressions in attributes, pragmas.

llvm-svn: 104083
2010-05-18 23:01:22 +00:00
Douglas Gregor 96cdb1590e Instantiate attributes on typedefs. This is a quick fix for PR7148,
when we really need a proper audit of our handling of attributes in
templates.

llvm-svn: 103999
2010-05-17 23:46:49 +00:00
Douglas Gregor f3d3ae665c Make sure to search semantic scopes and appropriate template-parameter
scopes during unqualified name lookup that has fallen out to namespace
scope. Fixes PR7133.

llvm-svn: 103766
2010-05-14 04:53:42 +00:00
Douglas Gregor 88d292ccb8 Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions. 

The new scheme:
  - For every use of a vtable, Sema calls MarkVTableUsed() to indicate
  the use. For example, this occurs when calling a virtual member
  function of the class, defining a constructor of that class type,
  dynamic_cast'ing from that type to a derived class, casting
  to/through a virtual base class, etc.
  - For every definition of a vtable, Sema calls MarkVTableUsed() to
  indicate the definition. This happens at the end of the translation
  unit for classes whose key function has been defined (so we can
  delay computation of the key function; see PR6564), and will also
  occur with explicit template instantiation definitions.
 - For every vtable defined/used, we mark all of the virtual member
 functions of that vtable as defined/used, unless we know that the key
 function is in another translation unit. This instantiates virtual
 member functions when needed.
  - At the end of the translation unit, Sema tells CodeGen (via the
  ASTConsumer) which vtables must be defined (CodeGen will define
  them) and which may be used (for which CodeGen will define the
  vtables lazily). 

From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).

Notes:
  (1) There's a ton of churn in the tests, because the order in which
  vtables get emitted to IR has changed. I've tried to isolate some of
  the larger tests from these issues.
  (2) Some diagnostics related to
  implicitly-instantiated/implicitly-defined virtual member functions
  have moved to the point of first use/definition. It's better this
  way.
  (3) I could use a review of the places where we MarkVTableUsed, to
  see if I missed any place where the language effectively requires a
  vtable.

Fixes PR7114 and PR6564.

llvm-svn: 103718
2010-05-13 16:44:06 +00:00
Douglas Gregor 17158425f2 Whenever we instantiate a function definition or class, enter a new
potentially-evaluated expression context, to ensure that used
declarations get properly marked. Fixes PR7123.

llvm-svn: 103624
2010-05-12 17:27:19 +00:00
Daniel Dunbar 0547ad38e3 Speculatively revert r103497, "Do not mark the virtual members of an
implicitly-instantiated class as ...", which seems to have broken bootstrap.

llvm-svn: 103515
2010-05-11 21:32:35 +00:00
Douglas Gregor 0c4aad15c2 Do not mark the virtual members of an implicitly-instantiated class as
referenced unless we see one of them defined (or the key function
defined, if it as one) or if we need the vtable for something. Fixes
PR7114.

llvm-svn: 103497
2010-05-11 20:24:17 +00:00
Douglas Gregor c97d7a2c6a The C++98/03 standard is disturbingly silent about out-of-scope
explicit instantiations of template. C++0x clarifies the intent
(they're ill-formed in some cases; see [temp.explicit] for
details). However, one could squint at the C++98/03 standard and
conclude they are permitted, so reduce the error to a warning
(controlled by -Wc++0x-compat) in C++98/03 mode.

llvm-svn: 103482
2010-05-11 17:39:34 +00:00
Douglas Gregor 112de35e5b Static data members intialized in-class that have constant values are
value-dependent if their initializers are value-dependent; my recent
tweak to these dependent rules overstepped by taking away this
value-dependents. Fixes a Boost.GIL regression.

llvm-svn: 103476
2010-05-11 16:41:27 +00:00
Douglas Gregor 0e4de76610 A DeclRefExpr that refers to a member function or a static data member
of the current instantiation is value-dependent. The C++ standard
fails to enumerate this case and, therefore, we missed it. Chandler
did all of the hard work of reducing the last remaining
Boost.PtrContainer failure (which had to do with static initialization
in the Serialization library) down to this simple little test.

While I'm at it, clean up the dependence rules for template arguments
that are declarations, and implement the dependence rules for template
argument packs.

llvm-svn: 103464
2010-05-11 08:41:30 +00:00
Chandler Carruth 6bd2d6c4be Add a test for a subtle instantiation pattern that showed up within a Boost
miscompile reduction. Clang already handles this correctly, but let's make sure
it stays that way.

llvm-svn: 103463
2010-05-11 08:02:08 +00:00
Douglas Gregor 14f232ea20 Improve our handling of the -Wunused-variable warning in templates. In
particular, don't complain about unused variables that have dependent
type until instantiation time, so that we can look at the type of the
variable. Moreover, only complain about unused variables that have
neither a user-declared constructor nor a non-trivial destructor.

llvm-svn: 103362
2010-05-08 23:05:03 +00:00
Douglas Gregor ff73a9e380 When instantiating statements that involve conditions (if, while, do,
for, and switch), be careful to construct the full expressions as soon
as we perform template instantation, so we don't either forget to call
temporary destructors or destroy temporaries at the wrong time. This
is the template-instantiation analogue to r103187, during which I
hadn't realized that the issue would affect the handling of these
constructs differently inside and outside of templates.

Fixes a regression in Boost.Function.

llvm-svn: 103357
2010-05-08 22:20:28 +00:00
Douglas Gregor 90cf2c98bb Record template argument deduction failures for member function
templates and conversion function templates. 

llvm-svn: 103349
2010-05-08 20:18:54 +00:00
Douglas Gregor d09efd43d3 When printing an overload candidate that failed due to SFINAE, print a
specific message that includes the template arguments, e.g.,

test/SemaTemplate/overload-candidates.cpp:27:20: note: candidate template
      ignored: substitution failure [with T = int *]
  typename T::type get_type(const T&); // expected-note{{candidate ...
                   ^

llvm-svn: 103348
2010-05-08 20:07:26 +00:00
Douglas Gregor 1d72edd7c5 Improve overload-candidate diagnostic for a function template that
failed because the explicitly-specified template arguments did not
match its template parameters, e.g.,

test/SemaTemplate/overload-candidates.cpp:18:8: note: candidate
template
      ignored: invalid explicitly-specified argument for template
      parameter 'I'
  void get(const T&);
       ^
test/SemaTemplate/overload-candidates.cpp:20:8: note: candidate
template
      ignored: invalid explicitly-specified argument for 1st template
      parameter
  void get(const T&);
       ^

llvm-svn: 103344
2010-05-08 19:15:54 +00:00
Douglas Gregor 3626a5cac2 When printing a non-viable overload candidate that failed due to
conflicting deduced template argument values, give a more specific
reason along with those values, e.g.,

test/SemaTemplate/overload-candidates.cpp:4:10: note: candidate template
      ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')
const T& min(const T&, const T&); 
         ^

llvm-svn: 103339
2010-05-08 17:41:32 +00:00
Douglas Gregor 5597ab4076 When we encounter a non-dependent type during template instantiation,
mark any declarations we see inside of that type as
"referenced". Fixes PR7079.

llvm-svn: 103323
2010-05-07 23:12:07 +00:00
Douglas Gregor 496e8b345c Reapply the reference-binding patch applied below, along with a fix to
ensure that we complete the type when we need to look at constructors
during reference binding.

When determining whether the two types involved in reference binding
are reference-compatible, reference-related, etc., do not complete the
type of the reference itself because it is not necessary to determine
well-formedness of the program. Complete the type that we are binding
to, since that can affect whether we know about a derived-to-base
conversion. 

Re-fixes PR7080.

llvm-svn: 103283
2010-05-07 19:42:26 +00:00
Douglas Gregor 56f14e575d Revert r103220. It seems to be breaking self-host
llvm-svn: 103259
2010-05-07 15:55:52 +00:00
Douglas Gregor d80c0238bb When determining whether the two types involved in reference binding
are reference-compatible, reference-related, etc., do not complete the
type of the reference itself because it is not necessary to determine
well-formedness of the program. Complete the type that we are binding
to, since that can affect whether we know about a derived-to-base
conversion. 

Fixes PR7080.

llvm-svn: 103220
2010-05-07 00:28:31 +00:00
Douglas Gregor e902956f59 Partial and full specializations of a class template may have a
different tag kind ("struct" vs. "class") than the primary template,
which has an affect on access control.

Should fix the last remaining Boost.Accumulors failure.

llvm-svn: 103144
2010-05-06 00:28:52 +00:00
Douglas Gregor b22ee88652 Support for 'template' as a disambiguator (PR7030)
ParseOptionalCXXScopeSpecifier() only annotates the subset of
    template-ids which are not subject to lexical ambiguity. Add support
    for the more general case in ParseUnqualifiedId() to handle cases
    such as A::template B().

    Also improve some diagnostic locations.

Fixes PR7030, from Alp Toker!

llvm-svn: 103081
2010-05-05 05:58:24 +00:00
Douglas Gregor c8be95274d When instantiating a function that was declared via a typedef, e.g.,
typedef int functype(int, int);
    functype func;

also instantiate the synthesized function parameters for the resulting
function declaration. 

With this change, Boost.Wave builds and passes all of its regression
tests.

llvm-svn: 103025
2010-05-04 18:18:31 +00:00
Douglas Gregor 1bd7a94460 When computing the template arguments for the instantiation of a
friend function template, be sure to adjust the computed template
argument lists based on the location of the definition of the function
template: it's possible that the definition we're instantiating with
and the template declaration that we found when creating the
specialization are in different contexts, which meant that we would
end up using the wrong template arguments for instantiation.

Fixes PR7013; all Boost.DynamicBitset tests now pass.

llvm-svn: 102974
2010-05-03 23:29:10 +00:00
Douglas Gregor 70b21be380 When instantiating a function-local variable definition, introduce the
mapping from the declaration in the template to the instantiated
declaration before transforming the initializer, in case some crazy
lunatic decides to use a variable in its own initializer. Fixes PR7016.

llvm-svn: 102945
2010-05-03 20:22:41 +00:00
Douglas Gregor cbbf3e3b4a It's okay to reference an enum in a template definition, even though
it's ill-formed to form an enum template. Fixes <rdar://problem/7933063>.

llvm-svn: 102926
2010-05-03 17:48:54 +00:00
Douglas Gregor 95c70ec678 When instantiating a member function declared via a typedef, don't try
to enter the instantiated parameter declarations into the local
instantiation scope; they can't be referenced anyway. Fixes PR7022.

llvm-svn: 102914
2010-05-03 15:32:18 +00:00
Douglas Gregor b139cd5843 Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators. 

Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.

This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:

  - For a class subobject, call the appropriate copy-assignment
    operator, after overload resolution has determined what that is.
  - For an array of scalar types or an array of class types that have
    trivial copy assignment operators, construct a call to
    __builtin_memcpy.
  - For an array of class types with non-trivial copy assignment
    operators, synthesize a (possibly nested!) for loop whose inner
    statement calls the copy constructor.
  - For a scalar type, use built-in assignment.

This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.

Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.

llvm-svn: 102853
2010-05-01 20:49:11 +00:00
Douglas Gregor fabf95d066 After substituting a template argument for a non-type template
parameter with pointer-to-member type, we may have to perform a
qualification conversion, since the pointee type of the parameter
might be more qualified than the pointee type of the argument we form
from the declaration. Fixes PR6986.

llvm-svn: 102777
2010-04-30 21:46:38 +00:00
Douglas Gregor 14cf752486 Clean up our handling of local instantiation scopes, which keep track
of the mapping from local declarations to their instantiated
counterparts during template instantiation. Previously, we tried to do
some unholy merging of local instantiation scopes that involved
storing a single hash table along with an "undo" list on the
side... which was ugly, and never handled function parameters
properly.

Now, we just keep separate hash tables for each local instantiation
scope, and "combining" two scopes means that we'll look in each of the
combined hash tables. The combined scope stack is rarely deep, and
this makes it easy to avoid the "undo" issues we were hitting. Also,
I've simplified the logic for function parameters: if we're declaring
a function and we need the function parameters to live longer, we just
push them back into the local instantiation scope where we need them. 

Fixes PR6990.

llvm-svn: 102732
2010-04-30 18:55:50 +00:00
Douglas Gregor 1e13c5a8fb When we start the definition of a class template, set the
InjectedClassNameType's Decl to point at the definition. It's a little
messy, but we do the same thing with classes and their record types,
since much of Clang expects that the TagDecl* one gets out of a type
is the definition. Fixes several Boost.Proto failures.

llvm-svn: 102691
2010-04-30 04:39:27 +00:00
John McCall 99b2fe5f54 Rebuild the nested name specifiers in member-pointer declarator chunks when
entering the current instantiation.  Set up a little to preserve type location
information for typename types while we're in there.

Fixes a Boost failure.

llvm-svn: 102673
2010-04-29 23:50:39 +00:00
Douglas Gregor 33dcc2e34d It turns out that we *can* end up having to display template argument
bindings when the template argument is still an expression; it happens
while checking the template arguments of a class template partial
specializations. Fixes PR6964.

llvm-svn: 102595
2010-04-29 04:55:13 +00:00
Douglas Gregor ea679ec125 Fix template instantiation for __builtin_offfsetof expressions that refer to members of anonymous structs/unions
llvm-svn: 102551
2010-04-28 22:43:14 +00:00
Douglas Gregor 882211c1da Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.

This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.

OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.

There are two major caveats to this patch:

  1) CodeGen cannot handle the case where __builtin_offsetof is not a
  constant expression, so it produces an error. So, to avoid
  regressing in C, we retain the old UnaryOperator-based
  __builtin_offsetof implementation in C while using the shiny new
  OffsetOfExpr implementation in C++. The old implementation can go
  away once we have proper CodeGen support for this case, which we
  expect won't cause much trouble in C++.

  2) __builtin_offsetof doesn't work well with non-POD class types,
  particularly when the designated field is found within a base
  class. I will address this in a subsequent patch.

Fixes PR5880 and a bunch of assertions when building Boost.Python
tests. 

llvm-svn: 102542
2010-04-28 22:16:22 +00:00
Douglas Gregor a02bb34155 When the qualifier of a id-expression is non-dependent but not
complete, return an error rather than falling back to building a
dependent declaration reference, since we might not be in a dependent
context. Fixes a fiendish crash-on-invalid in Boost.FunctionTypes that
I wasn't able to reduce to anything useful.

llvm-svn: 102491
2010-04-28 07:04:26 +00:00
Douglas Gregor 1614237822 When instantiating a function template specialization following
template argument deduction, use the lexical declaration context as
the owner for friend function templates. Fixes 2 failures in
Boost.Graph.

llvm-svn: 102489
2010-04-28 04:52:24 +00:00
Douglas Gregor da7be08a0c When instantiating UnresolvedLookupExpr and UnresolvedMemberExpr
expressions, be sure to set the naming class of the LookupResult
structure. Fixes PR6947.

llvm-svn: 102434
2010-04-27 16:10:10 +00:00
John McCall 1e67dd6b2f Improve the diagnostic you get when making a qualified member access
with a qualifier referencing a different type.

llvm-svn: 102409
2010-04-27 01:43:38 +00:00
John McCall 2408e32096 Make the InjectedClassNameType the canonical type of the current instantiation
of a class template or class template partial specialization.  That is to
say, in
  template <class T> class A { ... };
or
  template <class T> class B<const T*> { ... };
make 'A<T>' and 'B<const T*>' sugar for the corresponding InjectedClassNameType
when written inside the appropriate context.  This allows us to track the
current instantiation appropriately even inside AST routines.  It also allows
us to compute a DeclContext for a type much more efficiently, at some extra
cost every time we write a template specialization (which can be optimized,
but I've left it simple in this patch).

llvm-svn: 102407
2010-04-27 00:57:59 +00:00
Douglas Gregor d984815ed9 Ensure that we have completed a type before attempting initialization
on that type. Fixes several problems in Boost.Interprocess.

llvm-svn: 102339
2010-04-26 14:36:57 +00:00
Douglas Gregor d5c231e745 When we attempt to create a temporary object of class type, be sure
that the type we're copying is complete. 

Boost.Regex now builds, although it's failing its regression tests
with our favorite "Sema doesn't consider destructor as used."
assertion.

llvm-svn: 102271
2010-04-24 21:09:25 +00:00
Douglas Gregor 53ce178cef When we take the address of a declaration to bind it to a non-type
template parameter, by sure to mark that declaration as
"referenced". The Boost.Iterator library now passes all tests.

llvm-svn: 102256
2010-04-24 18:20:53 +00:00
Douglas Gregor 32f21a63ea Tweak test case slightly
llvm-svn: 102248
2010-04-24 16:40:35 +00:00
Douglas Gregor ba41d01b59 Be more careful around dependent nested-name-specifiers, complaining
when they are not complete (since we could not match them up to
anything) and ensuring that enum parsing can cope with dependent
elaborated-type-specifiers. Fixes PR6915 and PR6649.

llvm-svn: 102247
2010-04-24 16:38:41 +00:00
Douglas Gregor 83eb5032c0 When instantiating a typedef of an anonymous tag type, note in the tag
declaration that this typedef gives the tag a name. Fixes a problem
uncovered by Boost.GIL (Generic Image Library).

llvm-svn: 102180
2010-04-23 16:25:07 +00:00
Douglas Gregor 06f32b3aaf Strip cv-qualifiers when building C++ constructor and destructor
names.

llvm-svn: 102171
2010-04-23 04:51:46 +00:00
Douglas Gregor 4f4946aaaa Whenever we complain about a failed initialization of a function or
method parameter, provide a note pointing at the parameter itself so
the user does not have to manually look for the function/method being
called and match up parameters to arguments. For example, we now get:

t.c:4:5: warning: incompatible pointer types passing 'long *' to
parameter of
      type 'int *' [-pedantic]
  f(long_ptr);
    ^~~~~~~~
t.c:1:13: note: passing argument to parameter 'x' here
void f(int *x);
            ^

llvm-svn: 102038
2010-04-22 00:20:18 +00:00
Douglas Gregor 58c65652a8 Reword the note we emit when suppressing template instantiation contexts, per John's advice
llvm-svn: 101988
2010-04-21 05:40:43 +00:00
Douglas Gregor ffed1cb339 Introduce a limit on the depth of the template instantiation backtrace
we will print with each error that occurs during template
instantiation. When the backtrace is longer than that, we will print
N/2 of the innermost backtrace entries and N/2 of the outermost
backtrace entries, then skip the middle entries with a note such as:

  note: suppressed 2 template instantiation contexts; use
  -ftemplate-backtrace-limit=N to change the number of template
  instantiation entries shown

This should eliminate some excessively long backtraces that aren't
providing any value.

llvm-svn: 101882
2010-04-20 07:18:24 +00:00
Douglas Gregor 5ab1165531 Improve our handling of user-defined conversions as part of overload
resolution. There are two sources of problems involving user-defined
conversions that this change eliminates, along with providing simpler
interfaces for checking implicit conversions:

  - It eliminates a case of infinite recursion found in Boost.

  - It eliminates the search for the constructor needed to copy a temporary
    generated by an implicit conversion from overload
    resolution. Overload resolution assumes that, if it gets a value
    of the parameter's class type (or a derived class thereof), there
    is a way to copy if... even if there isn't. We now model this
    properly.

llvm-svn: 101680
2010-04-17 22:01:05 +00:00
Douglas Gregor b33eed0ced Collapse the three separate initialization paths in
TryStaticImplicitCast (for references, class types, and everything
else, respectively) into a single invocation of
InitializationSequence.

One of the paths (for class types) was the only client of
Sema::TryInitializationByConstructor, which I have eliminated. This
also simplified the interface for much of the cast-checking logic,
eliminating yet more code.

I've kept the representation of C++ functional casts with <> 1
arguments the same, despite the fact that I hate it. That fix will
come soon. To satisfy my paranoia, I've bootstrapped + tested Clang
with these changes.

llvm-svn: 101549
2010-04-16 22:09:46 +00:00
Douglas Gregor 064fdb2fe8 Always diagnose and complain about problems in
ResolveAddressOfOverloadedFunction when asked to complain. Previously,
we had some weird handshake where ResolveAddressOfOverloadedFunction
expected its caller to handle some of the diagnostics but not others,
and yet there was no way for the caller to know which case we were
in. Eliminate this madness, fixing <rdar://problem/7765884>.

llvm-svn: 101312
2010-04-14 23:11:21 +00:00
John McCall b723860aac Mark a function declaration invalid if any of its parameter declarations
are invalid.  Prevents a crash-on-invalid during template instantiation.
I... really don't understand how this wasn't already present.

llvm-svn: 101203
2010-04-14 01:27:20 +00:00
Douglas Gregor ce40e2ef8a Fix a crash-on-invalid involving name lookup of tag names, where we
ended up finding a function template that we didn't expect. Recover
more gracefully, and fix a similar issue for class templates.

llvm-svn: 101040
2010-04-12 16:00:01 +00:00
Douglas Gregor 940bca7b93 Be sure to instantiate the parameters of a function, even when the
function's type is (strictly speaking) non-dependent. This ensures
that, e.g., default function arguments get instantiated properly.

And, since I couldn't resist, collapse the two implementations of
function-parameter instantiation into calls to a single, new function
(Sema::SubstParmVarDecl), since the two had nearly identical code (and
each had bugs the other didn't!). More importantly, factored out the
semantic analysis of a parameter declaration into
Sema::CheckParameter, which is called both by
Sema::ActOnParamDeclarator (when parameters are parsed) and when a
parameter is instantiated. Previously, we were missing some
Objective-C and address-space checks on instantiated function
parameters.

Fixes PR6733.

llvm-svn: 101029
2010-04-12 07:48:19 +00:00
Sebastian Redl c72350ea9f When a member pointer is dereferenced, the class it points into must be complete. Enforce this.
llvm-svn: 100925
2010-04-10 10:14:54 +00:00
John McCall bb7b658ab5 Diagnose misordered initializers in constructor templates immediately instead of
when they're instantiated.  Merge the note into the -Wreorder warning;  it
doesn't really contribute much, and it was splitting a thought across diagnostics
anyway.  Don't crash in the parser when a constructor's initializers end in a
comma and there's no body;  the recovery here is still terrible, but anything's
better than a crash.

llvm-svn: 100922
2010-04-10 07:37:23 +00:00
John McCall 3155f573f5 Turn access control on by default in -cc1.
Remove -faccess-control from -cc1; add -fno-access-control.
Make the driver pass -fno-access-control by default.
Update a bunch of tests to be correct under access control.

llvm-svn: 100880
2010-04-09 19:03:51 +00:00
Douglas Gregor c68e140657 Improve diagnostics when we fail to convert from a source type to a
destination type for initialization, assignment, parameter-passing,
etc. The main issue fixed here is that we used rather confusing
wording for diagnostics such as

t.c:2:9: warning: initializing 'char const [2]' discards qualifiers,
      expected 'char *' [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

We're not initializing a 'char const [2]', we're initializing a 'char
*' with an expression of type 'char const [2]'. Similar problems
existed for other diagnostics in this area, so I've normalized them all
with more precise descriptive text to say what we're
initializing/converting/assigning/etc. from and to. The warning for
the code above is now:

t.c:2:9: warning: initializing 'char *' from an expression of type
      'char const [2]' discards qualifiers [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

Fixes <rdar://problem/7447179>.

llvm-svn: 100832
2010-04-09 00:35:39 +00:00
Douglas Gregor f19ac0ede9 Downgrade the "declaration does not declare anything" error to a
warning. It's not harmful to have such pointless declarations, and GCC
does not diagnose this issue consistently.

llvm-svn: 100814
2010-04-08 21:33:23 +00:00
Jeffrey Yasskin 54eba427ed Explain that a template needs arguments to make it into a type, for
variable declarations.

llvm-svn: 100809
2010-04-08 21:04:54 +00:00
Jeffrey Yasskin c76498d409 Make CXXScopeSpec invalid when incomplete, and propagate that into any
Declarator that depends on it.  This fixes several redundant errors and bad
recoveries.

llvm-svn: 100779
2010-04-08 16:38:48 +00:00
Jeffrey Yasskin 823015d627 When a template (without arguments) is passed as a template type
parameter, explicitly ask the user to give it arguments.  We used to
complain that it wasn't a type and expect the user to figure it out.

llvm-svn: 100729
2010-04-08 00:03:06 +00:00
Jeffrey Yasskin 4e150f8d35 Fix some redundant errors by changing CXXScopeSpec::isSet calls into
isNotEmpty calls.

llvm-svn: 100722
2010-04-07 23:29:58 +00:00
Anders Carlsson db0a965eca If a constructor is a dependent context, just set the base and member initializers as they are written. Fixes a bug where we wouldn't show initialization order warnings when instantiating.
llvm-svn: 100180
2010-04-02 06:26:44 +00:00
Douglas Gregor b242683d99 Overhaul checking of non-type template arguments that should refer to
an object or function. Our previous checking was too lax, and ended up
allowing missing or extraneous address-of operators, among other
evils. The new checking provides better diagnostics and adheres more
closely to the standard.

Fixes PR6563 and PR6749.

llvm-svn: 100125
2010-04-01 18:32:35 +00:00
Douglas Gregor f5af3584ca Improve diagnostics when an elaborated-type-specifer containing a
nested-name-specifier (e.g., "class T::foo") fails to find a tag
member in the scope nominated by the
nested-name-specifier. Previously, we gave a bland

  error: 'Nested' does not name a tag member in the specified scope

which didn't actually say where we were looking, which was rather
horrible when the nested-name-specifier was instantiated. Now, we give
something a bit better:

  error: no class named 'Nested' in 'NoDepBase<T>'

llvm-svn: 100060
2010-03-31 23:17:41 +00:00
Douglas Gregor e677dafce1 Change the representation of dependent elaborated-type-specifiers
(such as "class T::foo") from an ElaboratedType of a TypenameType to a
DependentNameType, which more accurately models the underlying
concept.

Improve template instantiation for DependentNameType nodes that
represent nested-name-specifiers, by performing tag name lookup and
checking the resulting tag appropriately. Fixes PR5681.

There is still much testing and cleanup to do in this area.

llvm-svn: 100054
2010-03-31 22:19:08 +00:00
Chandler Carruth b32b344c8f Re-bind non-dependent CXXTemporaryObjectExpr nodes as temporaries when
instantiating a template, which ensures the destructor is called. This fixes
PR6671.

llvm-svn: 100029
2010-03-31 18:34:58 +00:00
Douglas Gregor 607f14168a Improve diagnostics when printing a template instantiation backtrace
involving substitution of deduced template arguments into a class
template partial specialization or function template, or when
substituting explicitly-specific template arguments into a function
template. We now print the actual deduced argument bindings so the
user can see what got deduced.

llvm-svn: 99923
2010-03-30 20:35:20 +00:00
Douglas Gregor d5cb1ddb2c After performing template argument deduction for a function template,
check deduced non-type template arguments and template template
arguments against the template parameters for which they were deduced,
performing conversions as appropriate so that deduced template
arguments get the same treatment as explicitly-specified template
arguments. This is the bulk of PR6723.

Also keep track of whether deduction of a non-type template argument
came from an array bound (vs. anywhere else). With this information,
we enforce C++ [temp.deduct.type]p17, which requires exact type
matches when deduction deduces a non-type template argument from
something that is not an array bound.

Finally, when in a SFINAE context, translate the "zero sized
arrays are an extension" extension diagnostic into a hard error (for
better standard conformance), which was a minor part of PR6723.

llvm-svn: 99734
2010-03-28 02:42:43 +00:00
John McCall 93cc732ffc Properly account for redeclarations when explicitly instantiating class templates.
What happens here is that we actually turn the first declaration into a
definition, regardless of whether it was actually originally a definition,
and furthermore we do this all after we've instantiated all the declarations.
This exposes a bug in my DefinitionData patch where it was only setting the
DefinitionData for previous declarations, not future declarations.
Fortunately, there's an iterator for that.

llvm-svn: 99657
2010-03-26 21:56:38 +00:00
Douglas Gregor bb3d786213 Reinstate change to non-type template arguments of integral type, so
that we extend/truncate then correct the sign to convert the non-type
template argument to the template parameter's type. Previously, we
reported an error when the non-type template argument was out of
range; now we just warn.

llvm-svn: 99600
2010-03-26 02:38:37 +00:00
Douglas Gregor a14cb9fd38 Revert attempted fix for integral template arguments. It seems to have broken tramp3d-v4.
llvm-svn: 99583
2010-03-26 00:39:40 +00:00
Douglas Gregor 63eed63312 Warn when the conversion of an integral non-type template argument to
the type of its corresponding non-type template parameter changes the
value. Previously, we were diagnosing this as an error, which was
wrong. We give reasonably nice warnings like:

test/SemaTemplate/temp_arg_nontype.cpp💯10: warning: non-type template
      argument value '256' truncated to '0' for template parameter of type
      'unsigned char'
Overflow<256> *overflow3; // expected-warning{{non-type template ...
         ^~~
test/SemaTemplate/temp_arg_nontype.cpp:96:24: note: template parameter is
      declared here
template<unsigned char C> struct Overflow;
                       ^

llvm-svn: 99561
2010-03-25 22:21:04 +00:00
Douglas Gregor 66767ea93c Add another test for weird substitutions into function types during template argument deduction
llvm-svn: 99510
2010-03-25 15:42:11 +00:00
Douglas Gregor da61afaf9d Improve our handling of local instantiation scopes in two related ways:
- When substituting template arguments as part of template argument
    deduction, introduce a new local instantiation scope.
  - When substituting into a function prototype type, introduce a new
    "temporary" local instantiation scope that merges with its outer
    scope but also keeps track of any additions it makes, removing
    them when we exit that scope.

Fixes PR6700, where we were getting too much mixing of local
instantiation scopes due to template argument deduction that
substituted results into function types.

llvm-svn: 99509
2010-03-25 15:38:42 +00:00
John McCall 598b4405a6 Properly instantiate friend class template declarations and link them into
the redeclaration chain.  Recommitted from r99477 with a fix:  we need to
merge in default template arguments from previous declarations.

llvm-svn: 99496
2010-03-25 06:39:04 +00:00
Bob Wilson 63d45e51fb Revert 99477 since it appears to be breaking the clang-x86_64-darwin10-fnt
buildbot.  The tramp3d test fails.
--- Reverse-merging r99477 into '.':
U    test/SemaTemplate/friend-template.cpp
U    test/CXX/temp/temp.decls/temp.friend/p1.cpp
U    lib/Sema/SemaTemplateInstantiateDecl.cpp
U    lib/Sema/SemaAccess.cpp

llvm-svn: 99481
2010-03-25 04:40:43 +00:00
John McCall ac418d44ed Properly instantiate and link in friend-class-template declarations.
llvm-svn: 99477
2010-03-25 02:56:08 +00:00
Douglas Gregor dc76403cc1 When pulling apart an initializer that involves a CXXConstructExpr, do
not pick apart a CXXTemporaryObjectExpr because such an object
construction was explicitly written in the source code. Fixes PR6657.

llvm-svn: 99427
2010-03-24 21:22:47 +00:00
Douglas Gregor 5112157958 Each non-local class instantiation is its own local instantiation
scope. Fixes PR6619.

llvm-svn: 99377
2010-03-24 01:33:17 +00:00
John McCall f857e0bbe7 Perform access control even for the implicit destructor calls from implicit
destructor definitions.  Remove some code duplication.

llvm-svn: 98611
2010-03-16 05:36:30 +00:00
John McCall 45d878b0f0 Fix a self-host problem caused by this over-eager assertion. I'm not sure
there's a good equivalent that's actually true, unfortunately.

llvm-svn: 98253
2010-03-11 09:33:17 +00:00
John McCall 85f9055955 When pretty-printing tag types, only print the tag if we're in C (and
therefore not creating ElaboratedTypes, which are still pretty-printed
with the written tag).

Most of these testcase changes were done by script, so don't feel too
sorry for my fingers.

llvm-svn: 98149
2010-03-10 11:27:22 +00:00
John McCall e78aac41de Create a new InjectedClassNameType to represent bare-word references to the
injected class name of a class template or class template partial specialization.
This is a non-canonical type;  the canonical type is still a template 
specialization type.  This becomes the TypeForDecl of the pattern declaration,
which cleans up some amount of code (and complicates some other parts, but
whatever).

Fixes PR6326 and probably a few others, primarily by re-establishing a few
invariants about TypeLoc sizes.     

llvm-svn: 98134
2010-03-10 03:28:59 +00:00
Rafael Espindola e7113ca907 Delay codegen of vtables when handling implicit instantiations.
This fixes PR6474.

llvm-svn: 98123
2010-03-10 02:19:29 +00:00
Douglas Gregor 104ee00181 Downgrade errors when trying to catch a pointer or reference to
incomplete type to warnings; GCC (and EDG in GCC compatibility mode)
permit such handles. Fixes PR6527.

(For real this time)

llvm-svn: 97927
2010-03-08 01:47:36 +00:00
Chandler Carruth 3681e58d8b Revert r97925, it only contained the test updates not the actual fix.
llvm-svn: 97926
2010-03-08 00:41:19 +00:00
Douglas Gregor 254bba4095 Downgrade errors when trying to catch a pointer or reference to
incomplete type to warnings; GCC (and EDG in GCC compatibility mode)
permit such handles. Fixes PR6527.

llvm-svn: 97925
2010-03-07 23:28:27 +00:00
Douglas Gregor 281c486e1b Robustify callers that rebuild typename type nodes again NULL return
types. Fixes PR6463.

llvm-svn: 97924
2010-03-07 23:26:22 +00:00
Rafael Espindola 70e040d552 During codegen assert that any copy assignment, destructor or constructor that
we need to synthesize has been marked as used by Sema.

Change Sema to avoid these asserts.

llvm-svn: 97589
2010-03-02 21:28:26 +00:00
Douglas Gregor dc70c3abc0 Diagnose the declaration of enum templates. Also, be a bit more
careful about value-dependent enumerators. Fixes PR5786.

llvm-svn: 97570
2010-03-02 17:53:14 +00:00
Douglas Gregor 9bc6b7fc53 Use CXXTemporaryObjectExpr for explicitly-constructed temporaries. We
used to do this, but it got lost when we switched functional-style
cast syntax over to using the new initialization code. Fixes PR6457.

llvm-svn: 97568
2010-03-02 17:18:33 +00:00
Douglas Gregor c3eb801671 Add test case from PR5812, which works now.
llvm-svn: 97535
2010-03-02 01:36:28 +00:00
Chris Lattner e1582706b0 avoid issues with the new scope protector. Previously we'd error
with "address taken of label in protected scope, jump to it would have unknown effect on scope"

llvm-svn: 97495
2010-03-01 20:56:44 +00:00
Douglas Gregor 79e31db9a9 When looking for a redeclaration of a static variable, only look for redeclarations. Fixes PR6449
llvm-svn: 97478
2010-03-01 19:11:54 +00:00
Douglas Gregor aff9c1a033 When instantiating a function-scoped enum, make sure that it and its
enumeration constants get placed into the local instantiation hash
table. Fixes PR6375.

llvm-svn: 97471
2010-03-01 19:00:07 +00:00
Douglas Gregor 604c30299d Robustify instantiation of templates when there are errors in the
template definition. Do this both by being more tolerant of errors in
our asserts and by not dropping a variable declaration completely when
its initializer is ill-formed. Fixes the crash-on-invalid in PR6375,
but not the original issue.

llvm-svn: 97463
2010-03-01 18:27:54 +00:00
Douglas Gregor a04f2ca19a When looking for the instantiated declaration that corresponds to a
given declaration in a template, make sure that the context we're
searching through is complete. Fixes PR6376.

llvm-svn: 97444
2010-03-01 15:56:25 +00:00
Douglas Gregor beab56e923 Skip dependent virtual base classes; fixes PR6413.
llvm-svn: 97291
2010-02-27 00:25:28 +00:00
John McCall 1f476a1783 Fix an assertion-on-error during tentative constructor parsing by
propagating error conditions out of the various annotate-me-a-snowflake
routines.  Generally (but not universally) removes redundant diagnostics
as well as, you know, not crashing on bad code.  On the other hand,
I have just signed myself up to fix fiddly parser errors for the next
week.  Again.

llvm-svn: 97221
2010-02-26 08:45:28 +00:00
Douglas Gregor d2d9da08f3 Make sure to mark constructors, operator new, and operator delete as
used when we instantiate C++ new expressions, delete expressions, and
object-construction expressions. Fixes PR6424, although we can't test
all of it until we finish implementing lookup of "operator delete" for
new expressions (!).

llvm-svn: 97195
2010-02-26 00:38:10 +00:00
Douglas Gregor de550355c1 When we decide to re-use an existing CXXConstructExpr node, make sure
to mark the constructor as referenced. Fixes the narrow issue reported
in PR6424, but there are a few other places that I'll fix before
closing out that PR.

llvm-svn: 97185
2010-02-26 00:01:57 +00:00
Douglas Gregor 678f90df09 Use CXXPseudoDestructorExpr as the stored representation for dependent
expressions that look like pseudo-destructors, e.g.,

  p->T::~T()

where p has dependent type.

At template instantiate time, we determine whether we actually have a
pseudo-destructor or a member access, and funnel down to the
appropriate routine in Sema.

Fixes PR6380.

llvm-svn: 97092
2010-02-25 01:56:36 +00:00
Douglas Gregor 71ad477ab3 Do not try to instantiate invalid declarations. It's a recipe for
disaster. Fixes PR6161.

llvm-svn: 96371
2010-02-16 19:28:15 +00:00
Douglas Gregor fe17d2550b Improve parsing and instantiation of destructor names, so that we can
now cope with the destruction of types named as dependent templates,
e.g.,

  y->template Y<T>::~Y()

Nominally, we implement C++0x [basic.lookup.qual]p6. However, we don't
follow the letter of the standard here because that would fail to
parse

  template<typename T, typename U>
  X0<T, U>::~X0() { }

properly. The problem is captured in core issue 339, which gives some
(but not enough!) guidance. I expect to revisit this code when the
resolution of 339 is clear, and/or we start capturing better source
information for DeclarationNames.

Fixes PR6152.

llvm-svn: 96367
2010-02-16 19:09:40 +00:00
Chandler Carruth 3e0c140c50 Fix instantiation of template functions with local classes that contain virtual
methods.

llvm-svn: 96283
2010-02-15 22:12:26 +00:00
Chandler Carruth 6b4756a224 Skip implicit instantiation of templated variables where a more recent
redeclaration provides an explicit instantiation or is invalid.

llvm-svn: 96097
2010-02-13 10:17:50 +00:00
Douglas Gregor 04922cbb46 Fix a fiendinshly fun little type-canonicalization bug, where we were
rebuilding a typename type terminating in a template-id (with
dependent template name, naturally) as a TypenameType when, because
its context could be fully resolved, we should have been building it
as a QualifiedNameType. Fixes PR6268.

llvm-svn: 96084
2010-02-13 06:05:33 +00:00
Douglas Gregor e6565625f4 Migrate the mish-mash of declaration checks in
Sema::ActOnUninitializedDecl over to InitializationSequence (with
default initialization), eliminating redundancy. More importantly, we
now check that a const definition in C++ has an initilizer, which was
an #if 0'd code for many, many months. A few other tweaks were needed
to get everything working again:

  - Fix all of the places in the testsuite where we defined const
    objects without initializers (now that we diagnose this issue)
  - Teach instantiation of static data members to find the previous
    declaration, so that we build proper redeclaration
    chains. Previously, we had the redeclaration chain but built it
    too late to be useful, because...
  - Teach instantiation of static data member definitions not to try
    to check an initializer if a previous declaration already had an
    initializer. This makes sure that we don't complain about static
    const data members with in-class initializers and out-of-line
    definitions.
  - Move all of the incomplete-type checking logic out of
    Sema::FinalizeDeclaratorGroup; it makes more sense in
    ActOnUnitializedDecl.

There may still be a few places where we can improve these
diagnostics. I'll address that as a separate commit.

llvm-svn: 95657
2010-02-09 07:26:29 +00:00
Douglas Gregor 92354b6b55 Implement a specific diagnostic when a class template partial
specialization does not use any of its template parameters, then
recover far more gracefully. Fixes PR6181.

llvm-svn: 95629
2010-02-09 00:37:32 +00:00
Chandler Carruth c126311d3e Require a complete type before examining base classes during template argument
deduction. This requires refactoring the deduction to have access to the Sema
object instead of merely the ASTContext. Still leaves something to be desired
due to poor source location.

Fixes PR6257 and half of PR6259.

llvm-svn: 95528
2010-02-07 21:33:28 +00:00
John McCall 15dda3701a Use a substituted type when determining how to substitute in non-type template
params.  Don't insert addrof operations when matching against a pointer;
array/function conversions should take care of this for us, assuming the
argument type-checked in the first place.  Add a fixme where we seem to be
using a less-restrictive reference type than we should.

Fixes PR 6249.

llvm-svn: 95495
2010-02-06 10:23:53 +00:00
John McCall ce410662ce Teach Sema how to instantiate a local function declaration properly. Fixes
PR 5517.

llvm-svn: 95470
2010-02-06 01:50:47 +00:00
Douglas Gregor d225fa05bd Cope with finding the "instantiated" declaration when we are
type-checking within a template definition. In this case, the
"instantiated" declaration is just the declaration itself, found
within the current instantiation. Fixes PR6239.

llvm-svn: 95442
2010-02-05 22:40:03 +00:00
Douglas Gregor b9397108c5 Fix two issues with the substitution of template template parameters
when instantiating the declaration of a member template:
  - Only check if the have a template template argument at a specific position
  when we already know that we have template arguments at that level;
  otherwise, we're substituting for a level-reduced template template
  parameter. 
  - When trying to find an instantiated declaration for a template
  template parameter, look into the instantiated scope. This was a
  typo, where we had two checks for TemplateTypeParmDecl, one of
  which should have been a TemplateTemplateParmDecl.

With these changes, tramp3d-v4 passes -fsyntax-only.

llvm-svn: 95421
2010-02-05 19:54:12 +00:00
Douglas Gregor 7df89f5d18 When we're parsing an expression that may have looked like a
declaration, we can end up with template-id annotation tokens for
types that have not been converted into type annotation tokens. When
this is the case, translate the template-id into a type and parse as
an expression.

llvm-svn: 95404
2010-02-05 19:11:37 +00:00
Douglas Gregor 0ab7af6c28 A dependent initializer with zero arguments should return a NULL
initializer (for no initialization) rather than a ParenListExpr with
zero arguments in it.

llvm-svn: 95382
2010-02-05 07:56:11 +00:00
Douglas Gregor 8c702534cb Default function arguments for function template specializations
always come from the primary template, so gather the instantiation
template arguments from the primary template.

llvm-svn: 95380
2010-02-05 07:33:43 +00:00
Douglas Gregor 6ec89d4953 When adding ADL candidates for overloaded
post-increment/post-decrement operators, be sure to consider both
arguments. Fixes PR6237.

llvm-svn: 95361
2010-02-05 05:15:43 +00:00
Douglas Gregor 8a6d15d5ed When determining whether a scope specifier is complete, consider a
dependent DeclContext to be "complete". Fixes PR6236.

llvm-svn: 95359
2010-02-05 04:39:02 +00:00
Douglas Gregor eca8f5a49c When substituting the template argument for a pointer non-type
template parameter, perform array/function decay (if needed), take the
address of the argument (if needed), perform qualification conversions
(if needed), and remove any top-level cv-qualifiers from the resulting
expression. Fixes PR6226.

llvm-svn: 95309
2010-02-04 17:21:48 +00:00
Douglas Gregor 7dc5c17d92 When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.

This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:

  - Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
    when the declaration is in an anonymous namespace.
  - Added Type::getLinkage() to determine the linkage of a type, which
    is defined as the minimum linkage of the types (when we're dealing
    with a compound type that is not a struct/class/union).
  - Extended NamedDecl::getLinkage() to consider the linkage of the
    template arguments and template parameters of function template
    specializations and class template specializations.
  - Taught code generation to rely on NamedDecl::getLinkage() when
    determining the linkage of variables and functions, also
    considering the linkage of the types of those variables and
    functions (C++ only). Map UniqueExternalLinkage to internal
    linkage, taking out the explicit checks for
    isInAnonymousNamespace().

This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:

LLVM:
  Expected Passes    : 4006
  Expected Failures  : 32
  Unsupported Tests  : 40
  Unexpected Failures: 736

Clang:
  Expected Passes    : 1903
  Expected Failures  : 14
  Unexpected Failures: 75

Overall:
  Expected Passes    : 5909
  Expected Failures  : 46
  Unsupported Tests  : 40
  Unexpected Failures: 811

Still to do:
  - Improve testing
  - Check whether we should allow the presence of types with
  InternalLinkage (in addition to UniqueExternalLinkage) given
  variables/functions internal linkage in C++, as mentioned in
  PR5792. 
  - Determine how expensive the getLinkage() calls are in practice;
  consider caching the result in NamedDecl.
  - Assess the feasibility of Chris's idea in comment #1 of PR5792.

llvm-svn: 95216
2010-02-03 09:33:45 +00:00
John McCall 8b9ed55bfb Note that an overload candidate was non-viable because template argument
deduction failed.  Right now there's a very vague diagnostic for most cases
and a good diagnostic for incomplete deduction.

llvm-svn: 94988
2010-02-01 18:53:26 +00:00
Douglas Gregor 7ae2d7758f Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:

  - CXXBaseOrMemberInitializer now contains only a single initializer
    rather than a set of initialiation arguments + a constructor. The
    single initializer covers all aspects of initialization, including
    constructor calls as necessary but also cleanup of temporaries
    created by the initializer (which we never handled
    before!).

  - Rework + simplify code generation for CXXBaseOrMemberInitializers,
    since we can now just emit the initializer as an initializer.

  - Switched base and member initialization over to the new
    initialization code (InitializationSequence), so that it

  - Improved diagnostics for the new initialization code when
    initializing bases and members, to match the diagnostics produced
    by the previous (special-purpose) code.

  - Simplify the representation of type-checked constructor initializers in
    templates; instead of keeping the fully-type-checked AST, which is
    rather hard to undo at template instantiation time, throw away the
    type-checked AST and store the raw expressions in the AST. This
    simplifies instantiation, but loses a little but of information in
    the AST.

  - When type-checking implicit base or member initializers within a
    dependent context, don't add the generated initializers into the
    AST, because they'll look like they were explicit.

  - Record in CXXConstructExpr when the constructor call is to
  initialize a base class, so that CodeGen does not have to infer it
  from context. This ensures that we call the right kind of
  constructor.

There are also a few "opportunity" fixes here that were needed to not
regress, for example:

  - Diagnose default-initialization of a const-qualified class that
    does not have a user-declared default constructor. We had this
    diagnostic specifically for bases and members, but missed it for
    variables. That's fixed now.

  - When defining the implicit constructors, destructor, and
    copy-assignment operator, set the CurContext to that constructor
    when we're defining the body.

llvm-svn: 94952
2010-01-31 09:12:51 +00:00
Douglas Gregor 4b4844f88d When naming a function template via a qualified-id (or any other way
that ADL is suppressed), we need to build an
UnresolvedLookupExpr. Fixes PR6063, which was hitting Boost headers
pretty hard.

llvm-svn: 94814
2010-01-29 17:15:43 +00:00
Anders Carlsson c0ebb9412c Land test case.
llvm-svn: 94362
2010-01-24 05:50:37 +00:00
Anders Carlsson 73eb7cd351 Use the new init code for member subobjects.
llvm-svn: 94329
2010-01-23 20:20:40 +00:00
Douglas Gregor 9abe2377e7 Teach Sema::ActOnDependentTemplateName that a dependent template name
in a member access expression referring into the current instantiation
need not be resolved at template definition *if* the current
instantiation has any dependent base classes. Fixes PR6081.

llvm-svn: 93877
2010-01-19 16:01:07 +00:00
Douglas Gregor e9f3ac7b1b Another test case for PR6062
llvm-svn: 93872
2010-01-19 06:47:24 +00:00
Douglas Gregor a3b624aa55 In a mem-initializer, a nested-name-specifier followed by an
identifier always names a type. In the case of a dependent
nested-name-specifier, build a TypenameType to describe the dependent
base type. I'd like to move more of this behavior up into the parser,
but this fixes PR6062.

llvm-svn: 93871
2010-01-19 06:46:48 +00:00
Douglas Gregor 7f792cf329 Introduce a second queue of "local" pending implicit instantiation,
which are instantiations of the member functions of local
classes. These implicit instantiations have to occur at the same time
as---and in the same local instantiation scope as---the enclosing
function, since the member functions of the local class can refer to
locals within the enclosing function. This should really, really fix PR5764.

llvm-svn: 93666
2010-01-16 22:29:39 +00:00
Douglas Gregor edf8f39003 While determining when to parse inline member functions of a class,
distinguish between nested classes (whose member functions cannot be
parsed until the innermost non-nested class is complete) and local
classes (that are defined within a function but are not necessarily
nested). The upshot of this change, which fixes PR5764, is that the
bodies of member functions of local (non-nested) classes need to be
parsed when the local class is complete (and no later), since they may
refer to function-local static variables, typedefs, enums, etc.

llvm-svn: 93653
2010-01-16 20:52:59 +00:00
Douglas Gregor f5974fa0d5 When we are instantiating a member function of a local class, be sure
to merge the local instantiation scope with the outer local
instantiation scope, so that we can instantiate declarations from the
function owning the local class. Fixes an assert while instantiating
Boost.MPL's BOOST_MPL_ASSERT_MSG.

llvm-svn: 93651
2010-01-16 20:21:20 +00:00
Douglas Gregor e1ad8a105a Partial fix for PR6022, where we were complaining when a friend
function template declared within a class template did not match a
function in another scope. We really need to rework how
friends-in-templates are semantically checked.

llvm-svn: 93642
2010-01-16 18:09:52 +00:00
Douglas Gregor 5fcb51c09c When determining whether a DeclRefExpr is value-dependent when it
references a const variable of integral type, the initializer may be
in a different declaration than the one that name-lookup saw. Find the
initializer anyway. Fixes PR6045.

llvm-svn: 93514
2010-01-15 16:21:02 +00:00
Douglas Gregor 27b174f4c3 When determining whether the type is the current instantiation, strip
qualifiers. Fixes PR6021.

llvm-svn: 93513
2010-01-15 16:05:33 +00:00
John McCall 38836f0f39 Don't repeat lookup when instantiating resolved member expressions.
Adjust BuildMemberReferenceExpr to perform the inheritance check on implicit
member accesses, which can arise from unqualified lookups and therefore may
reference decls from enclosing class scopes.

Fixes PR 5838.

llvm-svn: 93510
2010-01-15 08:34:02 +00:00
Douglas Gregor d0d2ee0e4b When performing qualified name lookup into the current instantiation,
do not look into base classes if there are any dependent base
classes. Instead, note in the lookup result that we couldn't look into
any dependent bases. Use that new result kind to detect when this case
occurs, so that we can fall back to treating the type/value/etc. as a
member of an unknown specialization.

Fixes an issue where we were resolving lookup at template definition
time and then missing an ambiguity at template instantiation time.

llvm-svn: 93497
2010-01-15 01:44:47 +00:00
Douglas Gregor 04b1152aac After dyn_cast'ing, it generally makes sense to check the *output* of
the dyn_cast against NULL rather than the *input*. Fixes PR6025.

llvm-svn: 93435
2010-01-14 18:13:22 +00:00
Douglas Gregor d2e6a45722 When qualified lookup into the current instantiation fails (because it
finds nothing), and the current instantiation has dependent base
classes, treat the qualified lookup as if it referred to an unknown
specialization. Fixes PR6031.

llvm-svn: 93433
2010-01-14 17:47:39 +00:00
Douglas Gregor 9de54ea41b Reimplement constructor declarator parsing to cope with template-ids
that name constructors, the endless joys of out-of-line constructor
definitions, and various other corner cases that the previous hack
never imagined. Fixes PR5688 and tightens up semantic analysis for
constructor names.

Additionally, fixed a problem where we wouldn't properly enter the
declarator scope of a parenthesized declarator. We were entering the
scope, then leaving it when we saw the ")"; now, we re-enter the
declarator scope before parsing the parameter list.

Note that we are forced to perform some tentative parsing within a
class (call it C) to tell the difference between

  C(int); // constructor

and

  C (f)(int); // member function

which is rather unfortunate. And, although it isn't necessary for
correctness, we use the same tentative-parsing mechanism for
out-of-line constructors to improve diagnostics in icky cases like:

  C::C C::f(int); // error: C::C refers to the constructor name, but
                  // we complain nicely and recover by treating it as
                  // a type.

llvm-svn: 93322
2010-01-13 17:31:36 +00:00
John McCall e1ac8d1742 Improve the reporting of non-viable overload candidates by noting the reason
why the candidate is non-viable.  There's a lot we can do to improve this, but
it's a good start.  Further improvements should probably be integrated with the
bad-initialization reporting routines.

llvm-svn: 93277
2010-01-13 00:25:19 +00:00
Chris Lattner 7011795ee4 use DiagRuntimeBehavior to silence the div/rem by zero warning when
not in an evaluated context.  This removes some bogus warnings.

llvm-svn: 93258
2010-01-12 21:30:55 +00:00
Douglas Gregor 18473f329d Improve recovery for template-ids whose template-name doesn't actually
name a template, when they occur in a base-specifier. This is one of
the (few) places where we know for sure that an identifier followed by
a '<' must be a template name, so we can diagnose and recover well:

test/SemaTemplate/dependent-base-classes.cpp:9:16: error: missing
'template'
      keyword prior to dependent template name 'T::apply'
struct X1 : T::apply<U> { }; // expected-error{{missing 'template' ...
               ^
               template 
test/SemaTemplate/dependent-base-classes.cpp:12:13: error: unknown
template name
      'vector'
struct X2 : vector<T> { }; // expected-error{{unknown template name
'vector'}}
            ^
2 diagnostics generated.

llvm-svn: 93257
2010-01-12 21:28:44 +00:00
Chris Lattner faa5417264 implement PR6004, warning about divide and remainder by zero.
llvm-svn: 93256
2010-01-12 21:23:57 +00:00
Douglas Gregor 46c59614d3 Parse dependent template-ids in base clauses and member
initializers. This isn't actually in the C++ grammar (in any version),
but that's clearly an oversight: both GCC and EDG support this syntax,
and it's used within Boost code. I'll file a core issue proposing
precisely the change made here. Fixes PR6008.

llvm-svn: 93243
2010-01-12 17:52:59 +00:00
Douglas Gregor c119dd50c2 When determining whether a given name is a template in a dependent
context, do not attempt typo correction. This harms performance (as
Abramo noted) and can cause some amusing errors, as in this new
testcase.

llvm-svn: 93240
2010-01-12 17:06:20 +00:00
Douglas Gregor 88f3eb898a When performing name lookup into a scope, check that its entity is
non-NULL before looking at the entity itself.

llvm-svn: 93199
2010-01-11 22:40:45 +00:00
John McCall 0237485287 Improve the lead diagnostic for C++ object subscript expressions with
no viable overloads.  Use a different message when the class provides
no operator[] overloads at all; use it for operator(), too.

Partially addresses PR 5900.

llvm-svn: 92894
2010-01-07 02:04:15 +00:00
Douglas Gregor ccecc1bb43 Fix marking of virtual members for nested classes whose first non-pure virtual function has a body inlined in the class
llvm-svn: 92855
2010-01-06 20:27:16 +00:00
John McCall fd0b2f8fe4 Improve the diagnostics used to report implicitly-generated class members
as parts of overload sets.  Also, refer to constructors as 'constructors'
rather than functions.

Adjust a lot of tests.

llvm-svn: 92832
2010-01-06 09:43:14 +00:00