Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ Improvements to Clang's diagnostics
- Fixed fix-it hint for fold expressions. Clang now correctly places the suggested right
parenthesis when diagnosing malformed fold expressions. (#GH151787)
- Added fix-it hint for when scoped enumerations require explicit conversions for binary operations. (#GH24265)

- Constant template parameters are now type checked in template definitions,
including template template parameters.
- Fixed an issue where emitted format-signedness diagnostics were not associated with an appropriate
diagnostic id. Besides being incorrect from an API standpoint, this was user visible, e.g.:
"format specifies type 'unsigned int' but the argument has type 'int' [-Wformat]"
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Sema/SemaTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5482,9 +5482,7 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &ArgLoc,
if (NTTP->isParameterPack() && NTTP->isExpandedParameterPack())
NTTPType = NTTP->getExpansionType(ArgumentPackIndex);

if (NTTPType->isInstantiationDependentType() &&
!isa<TemplateTemplateParmDecl>(Template) &&
!Template->getDeclContext()->isDependentContext()) {
if (NTTPType->isInstantiationDependentType()) {
// Do substitution on the type of the non-type template parameter.
InstantiatingTemplate Inst(*this, TemplateLoc, Template, NTTP,
CTAI.SugaredConverted,
Expand All @@ -5494,6 +5492,7 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &ArgLoc,

MultiLevelTemplateArgumentList MLTAL(Template, CTAI.SugaredConverted,
/*Final=*/true);
MLTAL.addOuterRetainedLevels(NTTP->getDepth());
// If the parameter is a pack expansion, expand this slice of the pack.
if (auto *PET = NTTPType->getAs<PackExpansionType>()) {
Sema::ArgPackSubstIndexRAII SubstIndex(*this, ArgumentPackIndex);
Expand Down
24 changes: 15 additions & 9 deletions clang/test/SemaTemplate/temp_arg_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,8 @@ namespace CheckDependentNonTypeParamTypes {
X<int, long, 3> x;
}
void h() {
// FIXME: If we accept A<B> at all, it's not obvious what should happen
// here. While parsing the template, we form
// X<unsigned char, int, (unsigned char)1234>
// but in the final instantiation do we get
// B<unsigned char, int, (int)1234>
// or
// B<unsigned char, int, (int)(unsigned char)1234>
// ?
X<unsigned char, int, 1234> x;
int check[x.value == 1234 ? 1 : -1];
// expected-error@-1 {{evaluates to 1234, which cannot be narrowed to type 'unsigned char'}}
}
};

Expand All @@ -143,6 +135,20 @@ namespace CheckDependentNonTypeParamTypes {
ab.g();
ab.h();
}

template<class> struct C {
template<class T, T V> struct D {};
using T = D<char, 1234>;
// expected-error@-1 {{evaluates to 1234, which cannot be narrowed to type 'char'}}
};

template<class T> struct E {
template <template <T V> class TT> struct F {
using X = TT<1234>;
};
};
// FIXME: This should be rejected, as there are no valid instantiations for E<char>::F
template struct E<char>;
}

namespace PR32185 {
Expand Down