Commit Graph

983 Commits

Author SHA1 Message Date
David Blaikie 6df859d859 Bound member function diagnostic - suggest no-args calls and note overload candidates
Still missing cases for templates, but this is a step in the right
direction. Also omits suggestions that would be ambiguous (eg: void
func(int = 0); + void func(float = 0); func;)

llvm-svn: 183173
2013-06-04 00:28:46 +00:00
Richard Smith eebe125f77 Fix crash-on-invalid: only use TransformAddressOfOperand when transforming the
operand of a unary address-of expression, not for *all* expressions!

llvm-svn: 182436
2013-05-21 23:29:46 +00:00
Richard Trieu b48e62fb45 Check a pointer is not null before attempting to use it. This prevents a
crash on an explicit specialization of a member function in a class scope.

llvm-svn: 181971
2013-05-16 02:14:08 +00:00
Douglas Gregor b4eadc34e1 <rdar://problem/13806270> A template argument list is a constant-evaluated context.
llvm-svn: 181076
2013-05-03 23:44:54 +00:00
Douglas Gregor d2472d4cdb Use attribute argument information to determine when to parse attribute arguments as expressions.
This change partly addresses a heinous problem we have with the
parsing of attribute arguments that are a lone identifier. Previously,
we would end up parsing the 'align' attribute of this as an expression
"(Align)":

 template<unsigned Size, unsigned Align>
 class my_aligned_storage
 {
   __attribute__((align((Align)))) char storage[Size];
 };

while this would parse as a "parameter name" 'Align':

 template<unsigned Size, unsigned Align>
 class my_aligned_storage
 {
   __attribute__((align(Align))) char storage[Size];
 };

The code that handles the alignment attribute would completely ignore
the parameter name, so the while the first of these would do what's
expected, the second would silently be equivalent to

 template<unsigned Size, unsigned Align>
 class my_aligned_storage
 {
   __attribute__((align)) char storage[Size];
 };

i.e., use the maximal alignment rather than the specified alignment.

Address this by sniffing the "Args" provided in the TableGen
description of attributes. If the first argument is "obviously"
something that should be treated as an expression (rather than an
identifier to be matched later), parse it as an expression.

Fixes <rdar://problem/13700933>.

llvm-svn: 180973
2013-05-02 23:25:32 +00:00
Douglas Gregor 33ebfe36e5 Revert r180970; it's causing breakage.
llvm-svn: 180972
2013-05-02 23:15:45 +00:00
Douglas Gregor 44dff3f2dc Use attribute argument information to determine when to parse attribute arguments as expressions.
This change partly addresses a heinous problem we have with the
parsing of attribute arguments that are a lone identifier. Previously,
we would end up parsing the 'align' attribute of this as an expression
"(Align)":

  template<unsigned Size, unsigned Align>
  class my_aligned_storage
  {
    __attribute__((align((Align)))) char storage[Size];
  };

while this would parse as a "parameter name" 'Align':

  template<unsigned Size, unsigned Align>
  class my_aligned_storage
  {
    __attribute__((align(Align))) char storage[Size];
  };

The code that handles the alignment attribute would completely ignore
the parameter name, so the while the first of these would do what's
expected, the second would silently be equivalent to

  template<unsigned Size, unsigned Align>
  class my_aligned_storage
  {
    __attribute__((align)) char storage[Size];
  };

i.e., use the maximal alignment rather than the specified alignment.

Address this by sniffing the "Args" provided in the TableGen
description of attributes. If the first argument is "obviously"
something that should be treated as an expression (rather than an
identifier to be matched later), parse it as an expression.

Fixes <rdar://problem/13700933>.

llvm-svn: 180970
2013-05-02 23:08:12 +00:00
Richard Smith 27d807cc9c Don't treat a non-deduced 'auto' type as being type-dependent. Instead, there
are now two distinct canonical 'AutoType's: one is the undeduced 'auto'
placeholder type, and the other is a deduced-but-dependent type. All
deduced-to-a-non-dependent-type cases are still non-canonical.

llvm-svn: 180789
2013-04-30 13:56:41 +00:00
Richard Smith c8378952fb Keep the parser's template depth up to date when parsing local templates and
late-parsed templates. Patch by Faisal Vali!

llvm-svn: 180708
2013-04-29 11:55:38 +00:00
Richard Smith 07cea1911a Properly reenter multiple contexts when parsing a late-parsed function template
within a dependent context. Patch by Will Wilson (+clang-format)!

llvm-svn: 180702
2013-04-29 08:53:40 +00:00
Richard Smith a3519fa347 Fix an assertion failure / accepts-invalid in -fms-extensions mode. Don't build
a dependent-scope id expression when a templated member function of a
non-templated class references an unknown identifier, since instantiation won't
rebuild it (and we can tell at parse time that it'll never work). Based on a
patch by Faisal Vali!

llvm-svn: 180701
2013-04-29 08:45:27 +00:00
Jyotsna Verma ef35f3a682 Removing example-dynarray.cpp test since it's of no value.
llvm-svn: 180208
2013-04-24 18:44:44 +00:00
Richard Trieu e373235c7c Fix PR15634, better error message for template deduction failure.
When two template decls with the same name are used in this diagnostic,
force them to print their qualified names.  This changes the bad message of:

candidate template ignored: could not match 'array' against 'array'

to the better message of:

candidate template ignored: could not match 'NS2::array' against 'NS1::array'

llvm-svn: 179056
2013-04-08 21:11:40 +00:00
Jyotsna Verma abb1ed6952 XFAIL example-dynarray.cpp test for Hexagon as some of the header files
are unavailable on Hexagon.

llvm-svn: 178791
2013-04-04 20:56:42 +00:00
Richard Smith 89b466c603 Fold together the two implementations of 6.7.3p2 in SemaType. Fix two bugs, each of which was only present in one version:
* Give the right diagnostic for 'restrict' applied to a non-pointer, non-reference type.
 * Don't reject 'restrict' applied indirectly to an Objective-C object pointer type (eg, through template instantiation).

llvm-svn: 178200
2013-03-28 00:03:10 +00:00
Richard Smith deec07403c Don't reject __restrict applied to a dependent type; it might instantiate to a pointer or reference type.
llvm-svn: 178198
2013-03-27 23:36:39 +00:00
Douglas Gregor 45bb4834e9 <rdar://problem/13267210> Ensure that Sema::CompareReferenceRelationship returns consistent results with invalid types.
When Sema::RequireCompleteType() is given a class template
specialization type that then fails to instantiate, it returns
'true'. On subsequent invocations, it can return false. Make sure that
this difference doesn't change the result of
Sema::CompareReferenceRelationship, which is expected to remain stable
while we're checking an initialization sequence.

llvm-svn: 178088
2013-03-26 23:36:30 +00:00
John McCall e68672fed2 Flag that friend function definitions are "late parsed" so that
template instantiation will still consider them to be definitions
if we instantiate the containing class before we get around
to parsing the friend.

This seems like a legitimate use of "late template parsed" to me,
but I'd appreciate it if someone responsible for the MS feature
would look over this.

This file already appears to access AST nodes directly, which
is arguably not kosher in the parser, but the performance of this
path matters enough that perpetuating the sin is justifiable.
Probably we ought to reconsider this policy for very simple
manipulations like this.

The reason this entire thing is necessary is that
function template instantiation plays some very gross games
in order to not associate an instantiated function template
with the class it came from unless it's a definition, and
the reason *that's* necessary is that the AST currently
cannot represent the instantiation history of individual
function template declarations, but instead tracks it in
common for the entire function template.  That probably
prevents us from correctly reporting ill-formed calls to
ambiguously instantiated friend function templates.

rdar://12350696

llvm-svn: 177003
2013-03-14 05:13:41 +00:00
Douglas Gregor d831d955f6 <rdar://problem/13094134> Don't try to wire up typedef names for invalid anonymous tag declarations encountered during template instantiation.
llvm-svn: 176727
2013-03-08 22:15:15 +00:00
Douglas Gregor a88c55b571 <rdar://problem/13140795> Transform the scope type of a pseudo-destructor expression within the object scope.
We were transforming the scope type of a pseudo-destructor expression
(e.g., the first T in x->T::~T()) as a freestanding type, which meant
that dependent template specialization types here would stay dependent
even when no template parameters were named. This would eventually
mean that a dependent expression would end up in what should be
fully-instantiated ASTs, causing IRgen to assert.

llvm-svn: 176723
2013-03-08 21:25:01 +00:00
David Blaikie e750491ff3 Add quotation marks to template names in diagnostics.
llvm-svn: 176474
2013-03-05 06:21:38 +00:00
David Blaikie dc601e3a09 PR15360: nullptr as a non-type template argument to a function type non-type template parameter
llvm-svn: 176216
2013-02-27 22:10:40 +00:00
David Blaikie a985542ae0 Add test coverage for array to pointer decay in non-type template parameters.
Functionality committed in r172585 but tested the function case without the
array case.

llvm-svn: 176215
2013-02-27 22:10:37 +00:00
Richard Smith 44c247f0f0 Handle alignas(foo...) pack expansions.
llvm-svn: 175875
2013-02-22 08:32:16 +00:00
Richard Smith c084bd2888 PR15132: Replace "address expression must be an lvalue or a function
designator" diagnostic with more correct and more human-friendly "cannot take
address of rvalue of type 'T'".

For the case of & &T::f, provide a custom diagnostic, rather than unhelpfully
saying "cannot take address of rvalue of type '<overloaded function type>'".

For the case of &array_temporary, treat it just like a class temporary
(including allowing it as an extension); the existing diagnostic wording
for the class temporary case works fine.

llvm-svn: 174262
2013-02-02 02:14:45 +00:00
Richard Smith 44ecdbdc61 Improve 'failed template argument deduction' diagnostic for the case where we
have a direct mismatch between some component of the template and some
component of the argument. The diagnostic now says what the mismatch was, but
doesn't yet say which part of the template doesn't match.

llvm-svn: 174039
2013-01-31 05:19:49 +00:00
Douglas Gregor effe2a1e75 Apply adjustment to function- and array-typed non-type template
parameters (per C++ [temp.param]p8) when computing the type of a
reference to a non-type template parameter. Fixes <rdar://problem/13000548>.

llvm-svn: 172585
2013-01-16 00:52:15 +00:00
Richard Smith 21bae43fab PR14695: Fix assert from bad cast<>. Not every namespace is a NamespaceDecl; it might instead be a TranslationUnitDecl.
llvm-svn: 170976
2012-12-22 02:46:14 +00:00
Richard Smith 38a549bc42 Fix regression in r170489: when instantiating a direct initializer which is a
CXXScalarValueInitExpr (or an ImplicitValueInitExpr), strip it back down to an
empty pair of parentheses so that the initialization code can tell that we're
performing value-initialization.

llvm-svn: 170867
2012-12-21 08:13:35 +00:00
Alexander Kornienko 90ff607894 Implement AST dumper for Decls.
http://llvm-reviews.chandlerc.com/D52

Patch by Philip Craig!

llvm-svn: 170634
2012-12-20 02:09:13 +00:00
Richard Smith 4efa77fde4 Attempt to clarify a vexing-parse diagnostic.
llvm-svn: 170492
2012-12-19 03:15:32 +00:00
Richard Smith 503053a737 Fix assertion failure in self-host (and probably bogus template instantiation
too). When instantiating a direct-initializer, if we find it has zero
arguments, produce an empty ParenListExpr rather than returning a null
expression.

llvm-svn: 170490
2012-12-19 02:27:38 +00:00
Eli Friedman 07bab73c7f Using CanQualType::getAs<ArrayType> is unsafe; fix the code currently using it,
and make sure additional uses don't get introduced.  <rdar://problem/12858424>.

llvm-svn: 170081
2012-12-13 01:43:21 +00:00
Richard Smith 58db83d11d PR13098: If we're instantiating an overloaded binary operator and we could
determine which member function would be the callee from within the template
definition, don't pass that function as a "non-member function" to
CreateOverloadedBinOp. Instead, just rely on it to select the member function
for itself.

llvm-svn: 168818
2012-11-28 21:47:39 +00:00
Richard Smith dd2ca571ae PR14428: When instantiating a 'new' expression, if we had a non-dependent
initialization, don't rebuild it. Remove a couple of hacks which were trying to
work around this. Fix the special case for one-argument CXXConstructExprs to
not apply if the one argument is a default argument.

llvm-svn: 168582
2012-11-26 08:32:48 +00:00
Benjamin Kramer 90633e39fc Sema: Provide a valid source location when instantiating templates based on a CXXDefaultArgExpr.
Fixes PR13758.

llvm-svn: 168521
2012-11-23 17:04:52 +00:00
Richard Smith 4f6a2c4acb When we have a MemberExpr referring to an overloaded static member function,
and we resolve it to a specific function based on the type which it's used as,
don't forget to mark it as referenced.

Fixes a regression introduced in r167514.

llvm-svn: 167918
2012-11-14 07:06:31 +00:00
Nick Lewycky a21719d688 When filtering the list of associated namespaces so that we don't suggest people
add functions to namespace 'std', also filter out namespaces with '__' anywhere
in the name.

llvm-svn: 167786
2012-11-13 00:08:34 +00:00
Douglas Gregor dc97457178 Rework my implementation of circular-reference finding to not use
CXXRecordDecl::forallBases, which does *not* do what I need. Fixes the
failure introduced in r167651.

llvm-svn: 167668
2012-11-10 07:24:09 +00:00
Douglas Gregor 6200470112 Diagnostic circular inheritance involving dependent base classes. We
would have diagnosed this at instantiation time anyway, if only we
didn't hang on all of these test cases. Fixes <rdar://problem/12629723>

llvm-svn: 167651
2012-11-10 01:18:17 +00:00
Richard Smith de63d36fb2 PR13788: Don't perform checks on the initializer of a dependently-typed
variable. Previously we didn't notice the type was dependent if the only
dependence came from an array bound.

Patch by Brian Brooks!

llvm-svn: 167642
2012-11-09 23:03:14 +00:00
Richard Trieu 23bafad985 When template deduction fails on a derived class, try a template deduction on
the base class.  If the base class deduction succeeds, use those results.  If
it fails, keep using the results from the derived class template deduction.

This prevents an assertion later where the type of deduction failure doesn't
match up with the template deduction info.

llvm-svn: 167550
2012-11-07 21:17:13 +00:00
Richard Smith e10d304d20 PR11851 (and duplicates): Whenever a constexpr function is referenced,
instantiate it if it can be instantiated and implicitly define it if it can be
implicitly defined. This matches g++'s approach. Remove some cases from
SemaOverload which were marking functions as referenced when just planning how
overload resolution would proceed; such cases are not actually references.

llvm-svn: 167514
2012-11-07 01:14:25 +00:00
Eli Friedman c087c3f6c5 Add missing check to warning for packed attribute. PR14259.
llvm-svn: 167510
2012-11-07 00:35:20 +00:00
Richard Smith 40c180db13 When rebuilding a DependentScopeDeclRefExpr, perform a lookup into the scope
even if it's dependent, in case it now names a member of the current instantiation.

llvm-svn: 166496
2012-10-23 19:56:01 +00:00
Richard Smith db2630fb04 Unrevert r166268, reverted in r166272, with a fix for the issue which Nick
found: if an overloaded operator& is present before a template definition,
the expression &T::foo is represented as a CXXOperatorCallExpr, not as a
UnaryOperator, so we didn't notice that it's permitted to reference a non-static
data member of an unrelated class.

While investigating this, I discovered another problem in this area: we are
treating template default arguments as unevaluated contexts during substitution,
resulting in performing incorrect checks for uses of non-static data members in
C++11. That is not fixed by this patch (I'll look into this soon; it's related
to the failure to correctly instantiate constexpr function templates), but was
resulting in this bug not firing in C++11 mode (except with -Wc++98-compat).

Original message:

PR14124: When performing template instantiation of a qualified-id outside of a
class, diagnose if the qualified-id instantiates to a non-static class member.

llvm-svn: 166385
2012-10-21 03:28:35 +00:00
Andy Gibbs c6e68daac0 Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive.
llvm-svn: 166280
2012-10-19 12:44:48 +00:00
Nick Lewycky 2e3b716959 Revert r166268, this fix for a crash-on-invalid introduced a rejects-valid.
Richard has an unreduced testcase to work with.

llvm-svn: 166272
2012-10-19 08:08:02 +00:00
Richard Smith b2d6df5c95 PR14124: When performing template instantiation of a qualified-id outside of a
class, diagnose if the qualified-id instantiates to a non-static class member.

llvm-svn: 166268
2012-10-19 06:32:17 +00:00
Eli Friedman c681e5f608 Fix a regression from r164656.
llvm-svn: 164804
2012-09-27 22:13:33 +00:00