Isn't comma operator suppose to honor left-to-right associativity?

When I try it on this test case, it exhibits right-to-left associativity.

#include <iostream>



struct CBI;

struct EC;

struct CET;



struct CBI {

    CBI& operator,(const CBI& rhs)

        { return *const_cast<CBI*>(&rhs); }

};



struct EC : CBI {

    explicit EC(CET* cet) : cet_(cet)

        {}



    CET* cet_;

};



struct CET {

    CBI& operator,(const CBI& rhs) const

        { return *const_cast<CBI*>(&rhs); }



    operator EC&() const

        { return *new EC(const_cast<CET*>(this)); }

};



static const CET&

hello() {

    std::cout << "Hello " << std::endl;

    return *new CET();

}



static const CET&

world() {

    std::cout << "World " << std::endl;

    return *new CET();

}



static void

test_comma_operator(CBI&) {



}



int main()

{

    test_comma_operator ((

        hello(),

        world()

    ));

}



CLANG appears to do it right.


us01odcvde08782> clang++ -g test.cpp

us01odcvde08782> ./a.out

*Hello*

World

us01odcvde08782> g++ -g test.cpp

us01odcvde08782> ./a.out

World

*Hello*

us01odcvde08782>


I was using CentOS6.8 with gcc 6.2. However, trying other versions of GCC
didn't make any difference.


Is this a bug in GCC?

Reply via email to