Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Improve diagnostics for CTAD #92393

Open
hokein opened this issue May 16, 2024 · 2 comments
Open

[clang] Improve diagnostics for CTAD #92393

hokein opened this issue May 16, 2024 · 2 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@hokein
Copy link
Collaborator

hokein commented May 16, 2024

Consider the following example:

template<typename> concept False = false;

template <class T> 
struct Foo { 
    template <class U>
    requires False<U>
    Foo(T, U);
};

Foo abc(1, 2); // CTAD fails

This code is invalid as class template argument deduction fails, and the diagnostics emitted by clang are:

<source>:10:5: error: no viable constructor or deduction guide for deduction of template arguments of 'Foo'
   10 | Foo abc(1, 2);
      |     ^
<source>:7:5: note: candidate template ignored: constraints not satisfied [with T = int, U = int]
    7 |     Foo(T, U);
      |     ^
<source>:6:14: note: because 'int' does not satisfy 'False'
    6 |     requires False<U>
      |              ^
<source>:1:36: note: because 'false' evaluated to false
    1 | template<typename> concept False = false;
      |                                    ^
<source>:4:8: note: candidate function template not viable: requires 1 argument, but 2 were provided

We have two template candidates (auto(T, U) -> Foo<T>, auto (Foo<T>) -> Foo<T>), and both of them are not viable during the function overload resolution.

As noticed, the above diagnostic messages only mention "candidate template ignored", making it hard to identify which template candidate. The diagnostic position doesn't give much useful information as these templates are synthesized.

I think we can improve this by printing the function signature in the diagnostic message.

@hokein hokein added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer labels May 16, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 16, 2024

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

Consider the following example:
template&lt;typename&gt; concept False = false;

template &lt;class T&gt; 
struct Foo { 
    template &lt;class U&gt;
    requires False&lt;U&gt;
    Foo(T, U);
};

Foo abc(1, 2); // CTAD fails

This code is invalid as class template argument deduction fails, and the diagnostics emitted by clang are:

&lt;source&gt;:10:5: error: no viable constructor or deduction guide for deduction of template arguments of 'Foo'
   10 | Foo abc(1, 2);
      |     ^
&lt;source&gt;:7:5: note: candidate template ignored: constraints not satisfied [with T = int, U = int]
    7 |     Foo(T, U);
      |     ^
&lt;source&gt;:6:14: note: because 'int' does not satisfy 'False'
    6 |     requires False&lt;U&gt;
      |              ^
&lt;source&gt;:1:36: note: because 'false' evaluated to false
    1 | template&lt;typename&gt; concept False = false;
      |                                    ^
&lt;source&gt;:4:8: note: candidate function template not viable: requires 1 argument, but 2 were provided

We have two template candidates (auto(T, U) -&gt; Foo&lt;T&gt;, auto (Foo&lt;T&gt;) -&gt; Foo&lt;T&gt;), and both of them are not viable during the function overload resolution.

As noticed, the above diagnostic messages only mention "candidate template ignored", making it hard to identify which template candidate. The diagnostic position doesn't give much useful information as these templates are synthesized.

I think we can improve this by printing the function signature in the diagnostic message.

@shafik
Copy link
Collaborator

shafik commented May 16, 2024

Confirmed: https://godbolt.org/z/arjbKeYT7

@shafik shafik added the confirmed Verified by a second party label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants