Commit Graph

487 Commits

Author SHA1 Message Date
Richard Smith 2c3fb80b23 Remove accidentally-left-behind commented out code.
llvm-svn: 290485
2016-12-24 04:22:52 +00:00
Richard Smith e68a38f0a8 Fix crash if substitution fails during deduction of variable template partial specialization arguments.
llvm-svn: 290484
2016-12-24 04:20:31 +00:00
Richard Smith 792c22dbd4 When producing a name of a partial specialization in a diagnostic, use the
template arguments as written rather than the canonical template arguments,
so we print more user-friendly names for template parameters.

llvm-svn: 290483
2016-12-24 04:09:05 +00:00
Akira Hatanaka d644e021b5 [Sema] Fix handling of enumerators used as default arguments of lambda
expressions in a function or class template.

This patch makes the following changes:

- Create a DependentScopeDeclRefExpr for the default argument instead of
  a CXXDependentScopeMemberExpr.
- Pass CombineWithOuterScope=true so that the outer scope in which the
  enum is declared is searched for the instantiation of the enum. 

This is the first part of https://reviews.llvm.org/D23096. Fixes PR28795

rdar://problem/27535319

llvm-svn: 289914
2016-12-16 03:19:41 +00:00
Richard Smith 8dbc6b2617 Make diagnostic for use of default member initializer before enclosing class is
complete a little more general; it is produced in other cases than the one that
it previously talked about.

llvm-svn: 287713
2016-11-22 22:55:12 +00:00
Akira Hatanaka 40c15abe5f Fix spelling mistake.
llvm-svn: 285938
2016-11-03 17:11:28 +00:00
Akira Hatanaka 43556c14fe [Sema] Avoid instantiating templates only when UncompilableErrorOccurred
and FatalErrorOccurred are both set.

This fixes a crash that occurs when a warning promoted to a fatal error
leaves the AST in an incomplete state, and then later CFG analysis is
run on the incomplete AST.

rdar://problem/28558923

Differential Revision: https://reviews.llvm.org/D26166

llvm-svn: 285923
2016-11-03 15:04:58 +00:00
Richard Smith 5f274389d1 P0127R2: Support type deduction for types of non-type template parameters in
C++1z.

Patch by James Touton! Some bugfixes and rebasing by me.

llvm-svn: 282651
2016-09-28 23:55:27 +00:00
Richard Smith 54f18e8a85 PR12298 et al: don't recursively instantiate a template specialization from
within the instantiation of that same specialization. This could previously
happen for eagerly-instantiated function templates, variable templates,
exception specifications, default arguments, and a handful of other cases.

We still have an issue here for default template arguments that recursively
make use of themselves and likewise for substitution into the type of a
non-type template parameter, but in those cases we're producing a different
entity each time, so they should instead be caught by the instantiation depth
limit. However, currently we will typically run out of stack before we reach
it. :(

llvm-svn: 280190
2016-08-31 02:15:21 +00:00
Richard Smith 4b054b2665 PR29097: add an update record when we instantiate the default member
initializer of an imported field.

llvm-svn: 279667
2016-08-24 21:25:37 +00:00
Vassil Vassilev b21ee08e57 PR28794: Don't try to instantiate function templates which are not visible.
Reviewed by Richard Smith.

llvm-svn: 279164
2016-08-18 22:01:25 +00:00
Argyrios Kyrtzidis d798c05526 [AST] Keep track of the left brace source location of a tag decl.
This is useful for source modification tools. There will be a follow-up commit using it.

llvm-svn: 275590
2016-07-15 18:11:33 +00:00
David Majnemer 6fbeee307e [AST] Use ArrayRef in more interfaces
ArrayRef is a little better than passing around a pointer/length
pair.

No functional change is intended.

llvm-svn: 274732
2016-07-07 04:43:07 +00:00
Richard Smith 62f19e700d Implement C++17 P0386R2, inline variables. (The 'inline' specifier gives a
variable weak discardable linkage and partially-ordered initialization, and is
implied for constexpr static data members.)

llvm-svn: 273754
2016-06-25 00:15:56 +00:00
David Majnemer 59f7792136 Use more ArrayRefs
No functional change is intended, just a small refactoring.

llvm-svn: 273647
2016-06-24 04:05:48 +00:00
David Majnemer 76a256260e [Sema] Don't crash when a field w/ a mem-initializer clashes with a record name
It is possible for a field and a class to have the same name.  In such
cases, performing lookup for the field might return a result set with
more than one entry.  An overzealous assertion fired, causing us to
crash instead of using the non-class lookup result.

This fixes PR28060.

llvm-svn: 272247
2016-06-09 05:26:56 +00:00
Richard Smith e19b95d879 Produce better pretty stack traces from crashes in template instantiation: add
pretty stack trace entries for all cases where we instantiate the definition of
something, and include the fully-qualified name with template arguments in the
name of the instantiated entity.

llvm-svn: 270904
2016-05-26 20:23:13 +00:00
Hans Wennborg a86a83bb2e Re-commit r270748 "clang-cl: Treat dllimport explicit template instantiation definitions as declarations (PR27810, PR27811)"
Also make explicit instantiation decls not apply to nested classes when
targeting MSVC. That dll attributes are not inherited by inner classes
might be the explanation for MSVC's behaviour here.

llvm-svn: 270897
2016-05-26 19:42:56 +00:00
Richard Smith c2bebe9aca Preserve the FoundDecl when performing overload resolution for constructors.
This is in preparation for C++ P0136R1, which switches the model for inheriting
constructors over from synthesizing a constructor to finding base class
constructors (via using shadow decls) when looking for derived class
constructors.

llvm-svn: 269231
2016-05-11 20:37:46 +00:00
Richard Smith 6739a10cec [modules] Enforce the rules that an explicit or partial specialization must be
declared before it is used. Because we don't use normal name lookup to find
these, the normal code to filter out non-visible names from name lookup results
does not apply.

llvm-svn: 268585
2016-05-05 00:56:12 +00:00
Richard Smith c7649dc749 Make sure to perform dependent access checks when instantiating a
lambda-expression. We don't actually instantiate the closure type / operator()
in the template in order to produce the closure type / operator() in the
instantiation, so this isn't caught by the normal path.

llvm-svn: 264184
2016-03-23 20:07:07 +00:00
John McCall c8e321d4bc Fix the template instantiation of ExtParameterInfos; tests to follow.
llvm-svn: 262289
2016-03-01 02:09:25 +00:00
Reid Kleckner 5b64034a43 [dllexport] Sort out emission order of delayed exported classes
Relands r260194 with a fix. If we have a template that transitions from
an extern template to an explicitly instantiated dllexport template, we
would add that class to the delayed exported class list without flushing
it.

For explicit instantiations, we can just flush the list of delayed
classes immediately. We don't have to worry about the bug fixed in
r260194 in this case because explicit instantiations can only occur at
file and namespace scope.

Fixes PR26490.

llvm-svn: 262056
2016-02-26 19:51:02 +00:00
Reid Kleckner d809be40d2 Revert "Avoid forcing emission of delayed dllexported classes on template instantiation"
This reverts commit r260194.

It caused PR26549. There's probably a better way to do this also.

llvm-svn: 260241
2016-02-09 17:48:27 +00:00
Reid Kleckner f5f2f5f159 Avoid forcing emission of delayed dllexported classes on template instantiation
Fixes PR26490

llvm-svn: 260194
2016-02-09 02:51:17 +00:00
Nico Weber c097337493 Always build a new TypeSourceInfo for function templates with parameters
RecursiveASTVisitor::TraverseFunctionHelper() traverses a function's
ParmVarDecls by going to the function's getTypeSourceInfo if it exists, and
`DEF_TRAVERSE_TYPELOC(FunctionProtoType` then goes to the function's
ParmVarDecls.

For a function template that doesn't have parameters that explicitly depend on
the template parameter, we used to be clever and not build a new
TypeSourceInfo. That meant that when an instantiation of such a template is
visited, its TypeSourceInfo would point to the ParmVarDecls of the template,
not of the instantiation, which then confused clients of RecursiveASTVisitor.

So don't be clever for function templates that have parameters, even if none of
the parameters depend on the type.

Fixes PR26257.
http://reviews.llvm.org/D16478

llvm-svn: 259428
2016-02-01 22:31:51 +00:00
Craig Topper aa700cbd3a [Sema] ArrayRef-ize ActOnBaseSpecifiers. NFC
llvm-svn: 256478
2015-12-27 21:55:19 +00:00
Craig Topper e6337e1ebf Revert r256399 "[Sema] ArrayRef-ize ActOnBaseSpecifiers. NFC"
It broke lldb build.

llvm-svn: 256403
2015-12-25 00:36:02 +00:00
Craig Topper 99d235329f [Sema] ArrayRef-ize SubstExprs. NFC
llvm-svn: 256401
2015-12-24 23:58:29 +00:00
Craig Topper 6550a4b17e [Sema] ArrayRef-ize ActOnBaseSpecifiers. NFC
llvm-svn: 256399
2015-12-24 23:58:20 +00:00
John McCall dc40b618cf Correctly type-check the default arguments of local functions
when eagerly instantiating them.

rdar://23721638

llvm-svn: 255325
2015-12-11 01:56:36 +00:00
Richard Smith 42fd9efa38 Revert r107690 (for PR7417) and add a testcase that it breaks. The approach of
that change turns out to not be reasonable: mutating the AST of a parsed
template during instantiation is not a sound thing to do, does not work across
chained PCH / modules builds, and is in any case a special-case workaround to a
more general problem that should be solved centrally.

llvm-svn: 249342
2015-10-05 20:05:21 +00:00
James Y Knight 48fefa3724 Fix FunctionParmPackExpr::Create() to take a ParmVarDecl* array.
FunctionParmPackExpr actually stores an array of ParmVarDecl* (and
accessors return that). But, the FunctionParmPackExpr::Create()
constructor accepted an array of Decl *s instead.

It was easy for this mismatch to occur without any obvious sign of
something wrong, since both the store and the access used independent
'reinterpet_cast<XX>(this+1)' calls.

llvm-svn: 248905
2015-09-30 14:04:23 +00:00
Serge Pavlov 73c6a2448f Instantiate function declarations in instantiated functions.
If a function declaration is found inside a template function as in:

    template<class T> void f() {
      void g(int x = T::v) except(T::w);
    }

it must be instantiated along with the enclosing template function,
including default arguments and exception specification.

Together with the patch committed in r240974 this implements DR1484.

Differential Revision: http://reviews.llvm.org/D11194

llvm-svn: 245810
2015-08-23 10:22:28 +00:00
Hans Wennborg 99000c24c9 Delay emitting members of dllexport classes until the class is fully parsed (PR23542)
This enables Clang to correctly handle code such as:

  struct __declspec(dllexport) S {
    int x = 42;
  };

where it would otherwise error due to trying to generate the default
constructor before the in-class initializer for x has been parsed.

Differential Revision: http://reviews.llvm.org/D11850

llvm-svn: 245139
2015-08-15 01:18:16 +00:00
Justin Bogner c6ecb7c693 Sema: Allow null names to be passed in to isAcceptableTagRedeclaration
It's possible for TagRedeclarations to involve decls without a name,
ie, anonymous enums. We hit some undefined behaviour if we bind these
null names to the reference here.

We never dereference the name, so it's harmless if it's null - make it
a pointer to allow that.

Fixes the Modules/submodules-merge-defs.cpp test under ubsan.

llvm-svn: 241963
2015-07-10 23:05:47 +00:00
Serge Pavlov 3739f5e7c9 Instantiation of local class members.
If a function containing a local class is instantiated, instantiate
all of local class member, including default arguments and exception
specifications.

This change fixes PR21332 and thus implements DR1484.

Differential Revision: http://reviews.llvm.org/D9990

llvm-svn: 240974
2015-06-29 17:50:19 +00:00
Manuel Klimek 5eb6039f16 Fix crash-on-invalid bug in template instantiation.
Get rid of code-path that (according to Richard Smith) is not needed but
leads to a crasher bug when assuming a template has been fully
instantiated and thus has a definition.

llvm-svn: 240752
2015-06-26 02:15:04 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.

llvm-svn: 240270
2015-06-22 09:47:44 +00:00
Serge Pavlov e7ad831241 Limit set of types instantiated in FindInstantiatedDecl.
Starting from r236426 FindInstantiatedDecl may instantiate types that
are referenced before definition. This change limit the set of types
that can be instantiated by this function.

llvm-svn: 237434
2015-05-15 10:10:28 +00:00
Serge Pavlov 4c51174677 Instantiate incomplete class used in template method.
If a class is absent from instantiation and is incomplete, instantiate it as
an incomplete class thus avoiding compiler crash.

This change fixes PR18653.

Differential Revision: http://reviews.llvm.org/D8281

llvm-svn: 236426
2015-05-04 16:44:39 +00:00
Serge Pavlov 907233fd99 Combine instantiation context of field initializer with context of class.
Inclass initializer is instantiated in its own LocalInstantiationScope. It
causes problems when instantiating local classes - when instantiation scope
is searched for DeclContext of the field, the search fails. As a solution,
the instantiation scope of field initializer is combined with its outer
scope.

This patch fixes PR23194.

Differential Revision: http://reviews.llvm.org/D9258

llvm-svn: 236005
2015-04-28 17:58:47 +00:00
Richard Smith c38498f046 PR23334: Perform semantic checking of lambda capture initialization in the right context.
Previously we'd try to perform checks on the captures from the middle of
parsing the lambda's body, at the point where we detected that a variable
needed to be captured. This was wrong in a number of subtle ways. In
PR23334, we couldn't correctly handle the list of potential odr-uses
resulting from the capture, and our attempt to recover from that resulted
in a use-after-free.

We now defer building the initialization expression until we leave the lambda
body and return to the enclosing context, where the initialization does the
right thing. This patch only covers lambda-expressions, but we should apply
the same change to blocks and captured statements too.

llvm-svn: 235921
2015-04-27 21:27:54 +00:00
Richard Trieu b58413323d Change range-based for-loops to be -Wrange-loop-analysis clean.
No functionality change.

llvm-svn: 234964
2015-04-15 01:21:42 +00:00
Reid Kleckner 93f661a1da MS ABI: Build C++ default argument exprs for exported template classes
This was an omission from r232229.

llvm-svn: 232554
2015-03-17 21:51:43 +00:00
Benjamin Kramer 7761a04715 Sema: We can use delegating ctors now. NFC.
llvm-svn: 231488
2015-03-06 16:36:50 +00:00
David Majnemer 8c969eaf1a Sema: Disable template instantiation once a fatal error is raised
Fatal errors disable all further diagnostics.  Continuing to permit
template instantiation does nothing but make it take longer for clang to
finish with the TU.

Instead, halt all further instantiation.

Fixed in PR22396.

llvm-svn: 227556
2015-01-30 05:01:23 +00:00
Richard Smith 70b13043a2 PR22117: Fix a case where we would get confused about which function parameter
we're instantiating, if there's a ParmVarDecl within a FunctionDecl context
that is not a parameter of that function. Add some asserts to catch this kind
of issue more generally, and fix another bug exposed by those asserts where we
were missing a local instantiation scope around substitution of
explicitly-specified template arguments.

llvm-svn: 225490
2015-01-09 01:19:56 +00:00
Richard Smith 069ecf65e5 Fix crash-on-valid if a lambda-expression appears lexically directly within a
local class inside a template.

llvm-svn: 222476
2014-11-20 22:56:34 +00:00