History log of /llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp (Results 1 – 25 of 814)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# abc8812d 29-Jan-2025 Jason Rice <ricejasonf@gmail.com>

[Clang][P1061] Add stuctured binding packs (#121417)

This is an implementation of P1061 Structure Bindings Introduce a Pack
without the ability to use packs outside of templates. There is a couple
o

[Clang][P1061] Add stuctured binding packs (#121417)

This is an implementation of P1061 Structure Bindings Introduce a Pack
without the ability to use packs outside of templates. There is a couple
of ways the AST could have been sliced so let me know what you think.
The only part of this change that I am unsure of is the
serialization/deserialization stuff. I followed the implementation of
other Exprs, but I do not really know how it is tested. Thank you for
your time considering this.

---------

Co-authored-by: Yanzuo Liu <zwuis@outlook.com>

show more ...


# 07a0e2be 29-Jan-2025 Matheus Izvekov <mizvekov@gmail.com>

[clang] Track function template instantiation from definition (#112241)

This fixes instantiation of definition for friend function templates,
when the declaration found and the one containing the de

[clang] Track function template instantiation from definition (#112241)

This fixes instantiation of definition for friend function templates,
when the declaration found and the one containing the definition have
different template contexts.

In these cases, the the function declaration corresponding to the
definition is not available; it may not even be instantiated at all.

So this patch adds a bit which tracks which function template
declaration was instantiated from the member template. It's used to find
which primary template serves as a context for the purpose of
obtainining the template arguments needed to instantiate the definition.

Fixes #55509

Relanding patch, with no changes, after it was reverted due to revert of
commit this patch depended on.

show more ...


Revision tags: llvmorg-21-init
# e29c0858 28-Jan-2025 Matheus Izvekov <mizvekov@gmail.com>

[clang] disallow narrowing when matching template template parameters (#124313)

This fixes the core issue described in P3579, following the design
intent of P0522 to not introduce any new cases whe

[clang] disallow narrowing when matching template template parameters (#124313)

This fixes the core issue described in P3579, following the design
intent of P0522 to not introduce any new cases where a template template
parameter match is allowed for a template which is not valid for all
possible uses.

With this patch, narrowing conversions are disallowed for TTP matching.

This reuses the existing machinery for diagnosing narrowing in a
converted constant expression.
Since P0522 is a DR and we apply it all the way back to C++98, this
brings that machinery to use in older standards, in this very narrow
scope of TTP matching.

This still doesn't solve the ambiguity when partial ordering NTTPs of
different integral types, this is blocked by a different bug which will
be fixed in a subsequent patch (but the test cases are added).

show more ...


# 27c91730 27-Jan-2025 Younan Zhang <zyn7109@gmail.com>

[Clang] Remove unnecessary Decl transform & profiles for SizeOfPackExpr (#124533)

We used to always transform the pattern declaration for SizeOfPackExpr
to ensure the constraint expression's profile

[Clang] Remove unnecessary Decl transform & profiles for SizeOfPackExpr (#124533)

We used to always transform the pattern declaration for SizeOfPackExpr
to ensure the constraint expression's profile produced the desired
result. However, this approach failed to handle pack expansions when the
pack referred to function parameters. In such cases, the function
parameters were formerly expanded to 1 to avoid building Subst* nodes
(see e6974daa7). That workaround caused us to transform a pack without a
proper ArgumentPackSubstitutionIndex, leading to crashes when
transforming the pattern.

It turns out that profiling the pattern for partially substituted
SizeOfPackExprs is unnecessary because their transformed forms are also
profiled within the partial arguments.

Fixes https://github.com/llvm/llvm-project/issues/124161

show more ...


# 28ad8978 23-Jan-2025 Matheus Izvekov <mizvekov@gmail.com>

Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)

This patch relands the following PRs:
* #111711
* #107350
* #111457

All of these patches were reve

Reland: [clang] unified CWG2398 and P0522 changes; finishes implementation of P3310 (#124137)

This patch relands the following PRs:
* #111711
* #107350
* #111457

All of these patches were reverted due to an issue reported in
https://github.com/llvm/llvm-project/pull/111711#issuecomment-2406491485,
due to interdependencies.

---
[clang] Finish implementation of P0522

This finishes the clang implementation of P0522, getting rid
of the fallback to the old, pre-P0522 rules.

Before this patch, when partial ordering template template parameters,
we would perform, in order:
* If the old rules would match, we would accept it. Otherwise, don't
generate diagnostics yet.
* If the new rules would match, just accept it. Otherwise, don't
generate any diagnostics yet again.
* Apply the old rules again, this time with diagnostics.

This situation was far from ideal, as we would sometimes:
* Accept some things we shouldn't.
* Reject some things we shouldn't.
* Only diagnose rejection in terms of the old rules.

With this patch, we apply the P0522 rules throughout.

This needed to extend template argument deduction in order
to accept the historial rule for TTP matching pack parameter to non-pack
arguments.
This change also makes us accept some combinations of historical and P0522
allowances we wouldn't before.

It also fixes a bunch of bugs that were documented in the test suite,
which I am not sure there are issues already created for them.

This causes a lot of changes to the way these failures are diagnosed,
with related test suite churn.

The problem here is that the old rules were very simple and
non-recursive, making it easy to provide customized diagnostics,
and to keep them consistent with each other.

The new rules are a lot more complex and rely on template argument
deduction, substitutions, and they are recursive.

The approach taken here is to mostly rely on existing diagnostics,
and create a new instantiation context that keeps track of this context.

So for example when a substitution failure occurs, we use the error
produced there unmodified, and just attach notes to it explaining
that it occurred in the context of partial ordering this template
argument against that template parameter.

This diverges from the old diagnostics, which would lead with an
error pointing to the template argument, explain the problem
in subsequent notes, and produce a final note pointing to the parameter.

---
[clang] CWG2398: improve overload resolution backwards compat

With this change, we discriminate if the primary template and which partial
specializations would have participated in overload resolution prior to
P0522 changes.

We collect those in an initial set. If this set is not empty, or the
primary template would have matched, we proceed with this set as the
candidates for overload resolution.

Otherwise, we build a new overload set with everything else, and proceed
as usual.

---
[clang] Implement TTP 'reversed' pack matching for deduced function template calls.

Clang previously missed implementing P0522 pack matching
for deduced function template calls.

show more ...


# f5736aee 17-Jan-2025 Kazu Hirata <kazu@google.com>

[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#123284)

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast

[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#123284)

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Stored to be nonnull.

show more ...


Revision tags: llvmorg-19.1.7
# 3972ed57 08-Jan-2025 Younan Zhang <zyn7109@gmail.com>

Revert "[Clang] Implement CWG2369 "Ordering between constraints and substitution"" (#122130)

Unfortunately that breaks some code on Windows when lambdas come into
play, as reported in
https://github

Revert "[Clang] Implement CWG2369 "Ordering between constraints and substitution"" (#122130)

Unfortunately that breaks some code on Windows when lambdas come into
play, as reported in
https://github.com/llvm/llvm-project/pull/102857#issuecomment-2577861178

This reverts commit 96eced624e0f120155256033fdcb8342e7e58d6e.

show more ...


# 96eced62 05-Jan-2025 Younan Zhang <zyn7109@gmail.com>

[Clang] Implement CWG2369 "Ordering between constraints and substitution" (#102857)

This patch partially implements CWG2369 for non-lambda-constrained
functions.

Lambdas are left intact at this poi

[Clang] Implement CWG2369 "Ordering between constraints and substitution" (#102857)

This patch partially implements CWG2369 for non-lambda-constrained
functions.

Lambdas are left intact at this point because we need extra work to
correctly instantiate captures before the function instantiation.

As a premise of CWG2369, this patch also implements CWG2770 to ensure
the function parameters are instantiated on demand.

Closes https://github.com/llvm/llvm-project/issues/54440

show more ...


Revision tags: llvmorg-19.1.6, llvmorg-19.1.5
# 1e3e199e 27-Nov-2024 Kazu Hirata <kazu@google.com>

[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_

[Sema] Migrate away from PointerUnion::{is,get} (NFC) (#117498)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

show more ...


Revision tags: llvmorg-19.1.4
# 46d750be 16-Nov-2024 Kazu Hirata <kazu@google.com>

[Sema] Remove unused includes (NFC) (#116461)

Identified with misc-include-cleaner.


# dde802b1 15-Nov-2024 Sirraide <aeternalmail@gmail.com>

[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use DynamicRecursiveASTVisitor (#115144)

This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and
`StaticAnalysi

[Clang] [NFC] Refactor AST visitors in Sema and the static analyser to use DynamicRecursiveASTVisitor (#115144)

This pr refactors all recursive AST visitors in `Sema`, `Analyze`, and
`StaticAnalysis` to inherit from DRAV instead. This is over half of the
visitors that inherit from RAV directly.

See also #115132, #110040, #93462

LLVM Compile-Time Tracker link for this branch:
https://llvm-compile-time-tracker.com/compare.php?from=5adb5c05a2e9f31385fbba8b0436cbc07d91a44d&to=b58e589a86c06ba28d4d90613864d10be29aa5ba&stat=instructions%3Au

show more ...


# de2fad32 12-Nov-2024 Younan Zhang <zyn7109@gmail.com>

[Clang] Fix dependent expression handling for assumptions (#115646)

The function definition instantiation assumes any declarations used
inside are already transformed before transforming the body,

[Clang] Fix dependent expression handling for assumptions (#115646)

The function definition instantiation assumes any declarations used
inside are already transformed before transforming the body, so we need
to preserve the transformed expression of CXXAssumeAttr even if it is
not a constant expression. Moreover, the full expression of the
assumption should also entail a potential lambda capture transformation,
hence the call to ActOnFinishFullExpr() after TransformExpr().

Fixes #114787

show more ...


# 37b4df43 08-Nov-2024 Younan Zhang <zyn7109@gmail.com>

[Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (#115120)

In 463a4f150, we assumed that all the template argument packs are of
size 1 when normalizi

[Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (#115120)

In 463a4f150, we assumed that all the template argument packs are of
size 1 when normalizing a constraint expression because I mistakenly
thought those packs were obtained from their injected template
parameters. This was wrong because we might be checking constraints when
instantiating a friend declaration within a class template
specialization, where the parent class template is specialized with
non-dependent template arguments.

In that sense, we shouldn't assume any pack size nor expand anything in
such a scenario. Moreover, there are no intermediate (substituted but
unexpanded) AST nodes for template template parameters, so we have to
special-case their transformations by looking into the instantiation
scope instead of extracting anything from template arguments.

Fixes #115098

show more ...


# adb0d8dd 07-Nov-2024 Younan Zhang <zyn7109@gmail.com>

[Clang] Distinguish expanding-pack-in-place cases for SubstTemplateTypeParmTypes (#114220)

In 50e5411e4, we preserved the pack substitution index within
SubstTemplateTypeParmType nodes and performe

[Clang] Distinguish expanding-pack-in-place cases for SubstTemplateTypeParmTypes (#114220)

In 50e5411e4, we preserved the pack substitution index within
SubstTemplateTypeParmType nodes and performed in-place expansions of
packs such that type constraints on a lambda that serve as a pattern of
a fold expression could be evaluated if the type constraints contain any
packs that are expanded by the fold expression.

However, we made an incorrect assumption of the condition under which
in-place expansion should occur. For example, a SizeOfPackExpr case
relies on SubstTemplateTypeParmType nodes being transformed to
SubstTemplateTypeParmPackTypes rather than expanding them immediately in
place.

This fixes that by adding a flag to SubstTemplateTypeParmType to
discriminate such in-place expansion situations.

Fixes https://github.com/llvm/llvm-project/issues/113518

show more ...


# 44ab3805 06-Nov-2024 Krystian Stasiowski <sdkrystian@gmail.com>

Revert "Reapply "[Clang][Sema] Refactor collection of multi-level template argument lists (#106585, #111173)" (#111852)" (#115159)

This reverts commit 2bb3d3a3f32ffaef3d9b6a27db7f1941f0cb1136.


# 2904f809 06-Nov-2024 Krystian Stasiowski <sdkrystian@gmail.com>

Revert "[Clang][Sema] Use the correct injected template arguments for partial specializations when collecting multi-level template argument lists (#112381)" (#115157)

This reverts commit 9381c6fd04c

Revert "[Clang][Sema] Use the correct injected template arguments for partial specializations when collecting multi-level template argument lists (#112381)" (#115157)

This reverts commit 9381c6fd04cc16a7606633f57c96c11e58181ddb.

show more ...


# 79f4d8f0 06-Nov-2024 Krystian Stasiowski <sdkrystian@gmail.com>

Revert "Reapply "[Clang][Sema] Always use latest redeclaration of primary template" (#114569)" (#115156)

This reverts commit b24650e814e55d90acfc40acf045456c98f32b9c.


# b24650e8 01-Nov-2024 Krystian Stasiowski <sdkrystian@gmail.com>

Reapply "[Clang][Sema] Always use latest redeclaration of primary template" (#114569)

This patch reapplies #114258, fixing an infinite recursion bug in
`ASTImporter` that occurs when importing the

Reapply "[Clang][Sema] Always use latest redeclaration of primary template" (#114569)

This patch reapplies #114258, fixing an infinite recursion bug in
`ASTImporter` that occurs when importing the primary template of a class
template specialization when the latest redeclaration of that template
is a friend declaration in the primary template.

show more ...


# 4afa9787 30-Oct-2024 Felipe de Azevedo Piovezan <fpiovezan@apple.com>

Revert "[Clang][Sema] Always use latest redeclaration of primary template" (#114304)

Clang importer doesn't seem to work well with this change, see
discussion in the original PR.

Reverts llvm/ll

Revert "[Clang][Sema] Always use latest redeclaration of primary template" (#114304)

Clang importer doesn't seem to work well with this change, see
discussion in the original PR.

Reverts llvm/llvm-project#114258

show more ...


# 90786ada 30-Oct-2024 Krystian Stasiowski <sdkrystian@gmail.com>

[Clang][Sema] Always use latest redeclaration of primary template (#114258)

This patch fixes a couple of regressions introduced in #111852.

Consider:

```
template<typename T>
struct A
{

[Clang][Sema] Always use latest redeclaration of primary template (#114258)

This patch fixes a couple of regressions introduced in #111852.

Consider:

```
template<typename T>
struct A
{
template<bool U>
static constexpr bool f() requires U
{
return true;
}
};

template<>
template<bool U>
constexpr bool A<short>::f() requires U
{
return A<long>::f<U>();
}

template<>
template<bool U>
constexpr bool A<long>::f() requires U
{
return true;
}

static_assert(A<short>::f<true>()); // crash here
```

This crashes because when collecting template arguments from the _first_
declaration of `A<long>::f<true>` for constraint checking, we don't add
the template arguments from the enclosing class template specialization
because there exists another redeclaration that is a member
specialization.

This also fixes the following example, which happens for a similar
reason:
```
// input.cppm

export module input;

export template<int N>
constexpr int f();

template<int N>
struct A {
template<int J>
friend constexpr int f();
};

template struct A<0>;

template<int N>
constexpr int f() {
return N;
}
```

```
// input.cpp

import input;

static_assert(f<1>() == 1); // error: static assertion failed
```

show more ...


# 7d1e283b 30-Oct-2024 Krystian Stasiowski <sdkrystian@gmail.com>

[Clang][Sema] Ignore previous partial specializations of member templates explicitly specialized for an implicitly instantiated class template specialization (#113464)

Consider the following:
```

[Clang][Sema] Ignore previous partial specializations of member templates explicitly specialized for an implicitly instantiated class template specialization (#113464)

Consider the following:
```
template<typename T>
struct A {
template<typename U>
struct B {
static constexpr int x = 0; // #1
};

template<typename U>
struct B<U*> {
static constexpr int x = 1; // #2
};
};

template<>
template<typename U>
struct A<long>::B {
static constexpr int x = 2; // #3
};

static_assert(A<short>::B<int>::y == 0); // uses #1
static_assert(A<short>::B<int*>::y == 1); // uses #2

static_assert(A<long>::B<int>::y == 2); // uses #3
static_assert(A<long>::B<int*>::y == 2); // uses #3
```

According to [temp.spec.partial.member] p2:
> If the primary member template is explicitly specialized for a given
(implicit) specialization of the enclosing class template, the partial
specializations of the member template are ignored for this
specialization of the enclosing class template.
If a partial specialization of the member template is explicitly
specialized for a given (implicit) specialization of the enclosing class
template, the primary member template and its other partial
specializations are still considered for this specialization of the
enclosing class template.

The example above fails to compile because we currently don't implement
[temp.spec.partial.member] p2. This patch implements the wording, fixing #51051.

show more ...


# 639a7ac6 29-Oct-2024 Krystian Stasiowski <sdkrystian@gmail.com>

[Clang][AST] Store injected template arguments in TemplateParameterList (#113579)

Currently, we store injected template arguments in
`RedeclarableTemplateDecl::CommonBase`. This approach has a coup

[Clang][AST] Store injected template arguments in TemplateParameterList (#113579)

Currently, we store injected template arguments in
`RedeclarableTemplateDecl::CommonBase`. This approach has a couple
problems:
1. We can only access the injected template arguments of
`RedeclarableTemplateDecl` derived types, but other `Decl` kinds still
make use of the injected arguments (e.g.
`ClassTemplatePartialSpecializationDecl`,
`VarTemplatePartialSpecializationDecl`, and `TemplateTemplateParmDecl`).
2. Accessing the injected template arguments requires the common data
structure to be allocated. This may occur before we determine whether a
previous declaration exists (e.g. when comparing constraints), so if the
template _is_ a redeclaration, we end up discarding the common data
structure.

This patch moves the storage and access of injected template arguments
from `RedeclarableTemplateDecl` to `TemplateParameterList`.

show more ...


Revision tags: llvmorg-19.1.3
# 4dd55c56 24-Oct-2024 Jay Foad <jay.foad@amd.com>

[clang] Use {} instead of std::nullopt to initialize empty ArrayRef (#109399)

Follow up to #109133.


# 8536c2e9 22-Oct-2024 Vlad Serebrennikov <serebrennikov.vladislav@gmail.com>

[clang][NFC] Move `concepts::createSubstDiagAt` from AST to Sema (#113294)

This fixes layering violation introduced in
2fd01d75a863184766ee0c82b5c0fc8be172448a. The declaration is moved to
`SemaTe

[clang][NFC] Move `concepts::createSubstDiagAt` from AST to Sema (#113294)

This fixes layering violation introduced in
2fd01d75a863184766ee0c82b5c0fc8be172448a. The declaration is moved to
`SemaTemplateInstantiate` section of `Sema.h`, after the file where it's
implemented.

show more ...


# 09cc75e2 18-Oct-2024 Boaz Brickner <brickner@google.com>

[clang] Deduplicate the logic that only warns once when stack is almost full (#112552)

Zero diff in behavior.


12345678910>>...33