lundi 3 décembre 2018

Why some of the non constant expressions are allowed as operands of constexpr comma operator?

Consider a simple example:

int foo() {
    return 3;
}

template <int>
struct Bar {};

int a;

int main() {
    int b;
    //Bar<((void)foo(), 1)> bar1;  //case 1. compilation error as expected
    Bar<((void)a, 2)> bar2;        //case 2. no error (long shot but `a' has a linkage so maybe expected)
    Bar<((void)b, 3)> bar3;        //case 3. no error ? (`b' does not have linkage) 
    (void)bar2;
    (void)bar3;
}

I would say it is a bug but both latest [clang] and [gcc] accept the code some maybe I'm missing some relevant standard rule that makes the code valid?

Aucun commentaire:

Enregistrer un commentaire