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] Comparison between pointers to a string literal and some other object results in constant evaluation failure #92382

Open
frederick-vs-ja opened this issue May 16, 2024 · 1 comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@frederick-vs-ja
Copy link
Contributor

The following code snippet is incorrectly rejected by Clang (Godbolt link).

static_assert([]{
    char arr[1]{};
    return arr != "a";
}());

arr is not a potentially non-unique object, so it must have a different address from that of string literal object "a", even though the latte is a potentially non-unique object. As a result, arr != "a" has a specified result (true), so the static assertion should be accepted.

#49380 is related. But that issue involved comparison between pointers to different string literal objects, where it's very non-trivial to determine whether the result is unspecified.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label May 16, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels May 16, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 16, 2024

@llvm/issue-subscribers-clang-frontend

Author: A. Jiang (frederick-vs-ja)

The following code snippet is incorrectly rejected by Clang ([Godbolt link](https://godbolt.org/z/sYcjG6aTP)).
static_assert([]{
    char arr[1]{};
    return arr != "a";
}());

arr is not a potentially non-unique object, so it must have a different address from that of string literal object "a", even though the latte is a potentially non-unique object. As a result, arr != "a" has a specified result (true), so the static assertion should be accepted.

#49380 is related. But that issue involved comparison between pointers to different string literal objects, where it's very non-trivial to determine whether the result is unspecified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants