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 looses constexpr. #40438

Closed
DenisYaroshevskiy mannequin opened this issue Mar 16, 2019 · 17 comments
Closed

Clang looses constexpr. #40438

DenisYaroshevskiy mannequin opened this issue Mar 16, 2019 · 17 comments
Labels
bugzilla Issues migrated from bugzilla c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug

Comments

@DenisYaroshevskiy
Copy link
Mannequin

DenisYaroshevskiy mannequin commented Mar 16, 2019

Bugzilla Link 41093
Resolution INVALID
Resolved on Jun 29, 2020 09:29
Version unspecified
OS All
CC @DaemonSnake,@jonathanpoelen,@zygoloid,@rogerorr,@fiesh

Extended Description

The following code doesn't compile with clang and compiles with gcc.
https://gcc.godbolt.org/z/L6dcAu

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Mar 17, 2019

This is a GCC bug. This code:

constexpr void table_map_one_helper(const Table& t, OutTable& out_table, Op op) {
constexpr auto multi_s = t.math.template as_multi_s();
//...

is ill-formed, because the reference 't' cannot be used in a constant expression (naming a reference resolves it to the referenced object, which is unknown here).

You can fix your code by changing that to

constexpr auto multi_s = decltype(t.math)::template as_multi_s();

https://gcc.godbolt.org/z/MBb1-9

@DenisYaroshevskiy
Copy link
Mannequin Author

DenisYaroshevskiy mannequin commented Mar 17, 2019

Thank you, Richard.

Can you please clarify for me: the fact that the function is static doesn't matter - as soon as I reference any symbol that is not constexpr - my whole expression is not constexpr, correct?

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Mar 22, 2019

It's not entirely that simple: constexpr evaluation is symbolic evaluation, and:

void f(int n) {
constexpr bool b = &n == &n;
}

... is OK, because symbolic evaluation of that succeeds. The problem is specific to references. Any time you name a reference, the evaluation semantics of that expression involve resolving the reference to the object that it refers to, so that's immediately non-constant if the reference binding is not "visible" to the evaluation. For example:

void f(int &n) {
constexpr bool b = &n == &n;
}

... is an error, because we cannot resolve 'n' to the object it refers to. And that resolution is not delayed until it's needed; it happens the moment you name 'n'. So even this is ill-formed:

void f(int &n) {
constexpr bool b = (n, true);
}

... even though it doesn't try to read or write through the reference.

@DenisYaroshevskiy
Copy link
Mannequin Author

DenisYaroshevskiy mannequin commented Mar 23, 2019

Thanks!

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug #29085 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug #30060 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug #30972 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug llvm/llvm-bugzilla-archive#43732 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug #26067 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug #34365 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Jun 29, 2020

*** Bug llvm/llvm-bugzilla-archive#46499 has been marked as a duplicate of this bug. ***

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#43732

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#46499

@erichkeane
Copy link
Collaborator

mentioned in issue llvm/llvm-bugzilla-archive#46865

@pinskia
Copy link

pinskia commented Jul 3, 2024

Note https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2280r4.html changes this to be valid from invalid ...

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (e0e1e613-dccb-47a5-85db-3dc989429265)

| | | | --- | --- | | Bugzilla Link | [41093](https://llvm.org/bz41093) | | Resolution | INVALID | | Resolved on | Jun 29, 2020 09:29 | | Version | unspecified | | OS | All | | CC | @DaemonSnake,@jonathanpoelen,@zygoloid,@rogerorr,@fiesh |

Extended Description

The following code doesn't compile with clang and compiles with gcc.
https://gcc.godbolt.org/z/L6dcAu

@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
@shafik
Copy link
Collaborator

shafik commented Jul 3, 2024

This is really a dup of: #63139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++17 clang:frontend Language frontend issues, e.g. anything involving "Sema" invalid Resolved as invalid, i.e. not a bug
Projects
None yet
Development

No branches or pull requests

5 participants