Immediate functions returning void in Clang

Viewed 91

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?

0 Answers
Related