Skip to content

Commit 6bcef54

Browse files
committed
Ensure we disambiguate NTTP names when doing TemplateTree comparisons
835b99e did this when we printed the NTTPs while NOT doing a TemplateTree comparison, this does the same change for the TemplateTree mechanism as well, amking the diagnostics less confusing in these cases. Fixes: #66744
1 parent 6b8d04c commit 6bcef54

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ Bug Fixes to C++ Support
335335
- Clang now no longer asserts when an UnresolvedLookupExpr is used as an
336336
expression requirement. (`#66612 https://github.com/llvm/llvm-project/issues/66612`)
337337

338+
- Clang now disambiguates NTTP types when printing diagnostics where the
339+
NTTP types are compared with the 'diff' method.
340+
(`#66744 https://github.com/llvm/llvm-project/issues/66744`)
341+
338342
Bug Fixes to AST Handling
339343
^^^^^^^^^^^^^^^^^^^^^^^^^
340344
- Fixed an import failure of recursive friend class template.

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ class TemplateDiff {
18901890
// FIXME: Diffing the APValue would be neat.
18911891
// FIXME: Suppress this and use the full name of the declaration if the
18921892
// parameter is a pointer or reference.
1893+
TPO->getType().getUnqualifiedType().print(OS, Policy);
18931894
TPO->printAsInit(OS, Policy);
18941895
return;
18951896
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -std=c++20 -verify %s -o -
2+
3+
struct empty {};
4+
struct metre : empty { };
5+
struct second : empty { };
6+
template<auto, auto> struct divided_units : empty { };
7+
template<auto> struct quantity { }; // #QUANT
8+
9+
void use() {
10+
quantity<divided_units<metre{}, second{}>{}> q{};
11+
quantity<metre{}> q2 = q;
12+
// expected-error@-1 {{no viable conversion from 'quantity<divided_units<metre{}, second{}>{{}}>' to 'quantity<metre{{}}>'}}
13+
// expected-note@#QUANT {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'quantity<divided_units<metre{}, second{}>{}>' to 'const quantity<metre{{}}> &' for 1st argument}}
14+
// expected-note@#QUANT {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'quantity<divided_units<metre{}, second{}>{}>' to 'quantity<metre{{}}> &&' for 1st argument}}
15+
}
16+

clang/test/SemaCXX/cxx2a-nttp-printing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ template <int N> struct Str {
77

88
template <Str V> class ASCII {};
99

10-
void Foo(ASCII<"this nontype template argument is too long to print">); // expected-note {{no known conversion from 'ASCII<{"this nontype template argument is too long"}>' to 'ASCII<{"this nontype template argument is too long to print"}>'}}
11-
void Bar(ASCII<"this nttp argument is too short">); // expected-note {{no known conversion from 'ASCII<{{119, 97, 105, 116, 32, 97, 32, 115, 27, 99, 111, 110, 100, 0}}>' to 'ASCII<{"this nttp argument is too short"}>'}}
12-
void Meow(ASCII<"what|">); // expected-note {{no known conversion from 'ASCII<{"what??!"}>' to 'ASCII<{"what|"}>' for 1st argument}}
10+
void Foo(ASCII<"this nontype template argument is too long to print">); // expected-note {{no known conversion from 'ASCII<Str<43>{"this nontype template argument is too long"}>' to 'ASCII<Str<52>{"this nontype template argument is too long to print"}>'}}
11+
void Bar(ASCII<"this nttp argument is too short">); // expected-note {{no known conversion from 'ASCII<Str<14>{{119, 97, 105, 116, 32, 97, 32, 115, 27, 99, 111, 110, 100, 0}}>' to 'ASCII<Str<32>{"this nttp argument is too short"}>'}}
12+
void Meow(ASCII<"what|">); // expected-note {{no known conversion from 'ASCII<Str<8>{"what??!"}>' to 'ASCII<Str<6>{"what|"}>' for 1st argument}}
1313

1414
void test_ascii() {
1515
ASCII<"this nontype template argument"

0 commit comments

Comments
 (0)