4

Clang++ produces linker error if one calls immediate function returning void not from a context of another immediate function as in the example:

consteval void f(int * x) { 
    if(x) *x = 1; 
}

consteval int g() {
    int y = 0;
    f(&y);
    return y;
}

int main() {
    (void)g(); //ok everywhere
    f(nullptr); //linker error in Clang
}

The error is:

undefined reference to `f(int*)'

Demo: https://gcc.godbolt.org/z/PT8ezfnrW

The error disappears if the immediate function returns anything but void, for example:

consteval int f(int * x) { 
    if(x) *x = 1; 
    return 1;
}

Demo: https://gcc.godbolt.org/z/hfzrM688E

Is it just a bug in Clang?

Fedor
  • 17,146
  • 13
  • 40
  • 131
  • 1
    https://stackoverflow.com/questions/63364918/clang-says-call-to-void-consteval-function-is-not-a-constant-expression – KamilCuk Oct 10 '21 at 10:00
  • @KamilCuk, thanks for the reference. It is said there that the bug is fixed, but it does not look so. At least it is manifested differently now. – Fedor Oct 10 '21 at 10:14
  • LLVM bugzilla and stackoverflow are 2 distinctly different websites. And this here is an obvious bug. :-) – oakad Oct 10 '21 at 10:43
  • Add these to the top of the file: `#ifndef __cpp_consteval` and `#error consteval not supported` and `#endif` – Eljay Oct 10 '21 at 12:47
  • Hmm, this must be a bug. There shouldn't be anything to link if it's `consteval`. – cigien Oct 10 '21 at 16:09
  • I reported this bug to llvm: https://bugs.llvm.org/show_bug.cgi?id=52183 – Fedor Oct 15 '21 at 09:24

0 Answers0