Skip to content

Diagnostic for constraint satisfication failure can provide irrelevant information #54678

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

Closed
brevzin opened this issue Mar 31, 2022 · 1 comment
Assignees
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@brevzin
Copy link
Contributor

brevzin commented Mar 31, 2022

Here's an example:

template<class>
concept True = true;

template<class>
concept False = false;

template<class>
concept Irrelevant = false;

template<class T> void foo(T t) requires (True<T> || Irrelevant<T>) && False<T> { }
template<class T> void bar(T t) requires (Irrelevant<T> || True<T>) && False<T> { }

int main() {
    foo(42);
    bar(42L);
}

The calls to foo(42) and bar(42L) should (and do) fail, because neither int nor long satisfy False.

clang currently emits this error for foo(42)

<source>:14:5: error: no matching function for call to 'foo'
    foo(42);
    ^~~
<source>:10:24: note: candidate template ignored: constraints not satisfied [with T = int]
template<class T> void foo(T t) requires (True<T> || Irrelevant<T>) && False<T> { }
                       ^
<source>:10:72: note: because 'int' does not satisfy 'False'
template<class T> void foo(T t) requires (True<T> || Irrelevant<T>) && False<T> { }
                                                                       ^
<source>:5:17: note: because 'false' evaluated to false
concept False = false;
                ^

Which is good.

But it emits this error for bar(42L):

<source>:15:5: error: no matching function for call to 'bar'
    bar(42L);
    ^~~
<source>:11:24: note: candidate template ignored: constraints not satisfied [with T = long]
template<class T> void bar(T t) requires (Irrelevant<T> || True<T>) && False<T> { }
                       ^
<source>:11:43: note: because 'long' does not satisfy 'Irrelevant'
template<class T> void bar(T t) requires (Irrelevant<T> || True<T>) && False<T> { }
                                          ^
<source>:8:22: note: because 'false' evaluated to false
concept Irrelevant = false;
                     ^
<source>:11:72: note: and 'long' does not satisfy 'False'
template<class T> void bar(T t) requires (Irrelevant<T> || True<T>) && False<T> { }
                                                                       ^
<source>:5:17: note: because 'false' evaluated to false
concept False = false;
                ^

This notes both that long does not satisfy False but also that long does not satisfy Irrelevant. But Irrelevant is irrelevant - that part of the disjunction holds (because long satisfies True), so that is not the reason this fails. It's just an irrelevant diagnostic to the user -- which clang (correctly) doesn't provide in the foo case.

@brevzin brevzin changed the title Diagnostics for constraint satisfication failure aren't useful Diagnostic for constraint satisfication failure can provide irrelevant information Mar 31, 2022
@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Mar 31, 2022
@hazohelet
Copy link
Member

@hazohelet hazohelet self-assigned this Aug 9, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
…ion failure

BEFORE this patch, when clang handles constraints like C1 || C2 where C1 evaluates to false and C2 evaluates to true, it emitted irrelevant diagnostics about the falsity of C1.
This patch removes the irrelevant diagnostic information generated during the evaluation of C1 if C2 evaluates to true.

Fixes llvm#54678

Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D157526
zahiraam pushed a commit to tahonermann/llvm-project that referenced this issue Oct 24, 2023
…ion failure

BEFORE this patch, when clang handles constraints like C1 || C2 where C1 evaluates to false and C2 evaluates to true, it emitted irrelevant diagnostics about the falsity of C1.
This patch removes the irrelevant diagnostic information generated during the evaluation of C1 if C2 evaluates to true.

Fixes llvm#54678

Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D157526
zahiraam pushed a commit to tahonermann/llvm-project that referenced this issue Oct 24, 2023
…ion failure

BEFORE this patch, when clang handles constraints like C1 || C2 where C1 evaluates to false and C2 evaluates to true, it emitted irrelevant diagnostics about the falsity of C1.
This patch removes the irrelevant diagnostic information generated during the evaluation of C1 if C2 evaluates to true.

Fixes llvm#54678

Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D157526
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
Projects
None yet
Development

No branches or pull requests

3 participants