Immediate functions returning void in Clang
Asked Answered
R

0

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?

Roble answered 10/10, 2021 at 9:34 Comment(6)
#63365418Rumble
@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.Roble
LLVM bugzilla and stackoverflow are 2 distinctly different websites. And this here is an obvious bug. :-)Smalto
Add these to the top of the file: #ifndef __cpp_consteval and #error consteval not supported and #endifMerv
Hmm, this must be a bug. There shouldn't be anything to link if it's consteval.Unshakable
I reported this bug to llvm: bugs.llvm.org/show_bug.cgi?id=52183Roble

© 2022 - 2024 — McMap. All rights reserved.