Skip to content

Commit

Permalink
Ensure we disambiguate NTTP names when doing TemplateTree comparisons
Browse files Browse the repository at this point in the history
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
  • Loading branch information
erichkeane committed Sep 21, 2023
1 parent 6b8d04c commit 6bcef54
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ Bug Fixes to C++ Support
- Clang now no longer asserts when an UnresolvedLookupExpr is used as an
expression requirement. (`#66612 https://github.com/llvm/llvm-project/issues/66612`)

- Clang now disambiguates NTTP types when printing diagnostics where the
NTTP types are compared with the 'diff' method.
(`#66744 https://github.com/llvm/llvm-project/issues/66744`)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ASTDiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,7 @@ class TemplateDiff {
// FIXME: Diffing the APValue would be neat.
// FIXME: Suppress this and use the full name of the declaration if the
// parameter is a pointer or reference.
TPO->getType().getUnqualifiedType().print(OS, Policy);
TPO->printAsInit(OS, Policy);
return;
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/AST/ast-nttp-template-tree-compares.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -std=c++20 -verify %s -o -

struct empty {};
struct metre : empty { };
struct second : empty { };
template<auto, auto> struct divided_units : empty { };
template<auto> struct quantity { }; // #QUANT

void use() {
quantity<divided_units<metre{}, second{}>{}> q{};
quantity<metre{}> q2 = q;
// expected-error@-1 {{no viable conversion from 'quantity<divided_units<metre{}, second{}>{{}}>' to 'quantity<metre{{}}>'}}
// 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}}
// 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}}
}

6 changes: 3 additions & 3 deletions clang/test/SemaCXX/cxx2a-nttp-printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ template <int N> struct Str {

template <Str V> class ASCII {};

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"}>'}}
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"}>'}}
void Meow(ASCII<"what|">); // expected-note {{no known conversion from 'ASCII<{"what??!"}>' to 'ASCII<{"what|"}>' for 1st argument}}
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"}>'}}
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"}>'}}
void Meow(ASCII<"what|">); // expected-note {{no known conversion from 'ASCII<Str<8>{"what??!"}>' to 'ASCII<Str<6>{"what|"}>' for 1st argument}}

void test_ascii() {
ASCII<"this nontype template argument"
Expand Down

0 comments on commit 6bcef54

Please sign in to comment.