jeudi 28 avril 2016

strange behaviour of using statements in g++

Consider following program:

namespace s1 {
 int m;
}
namespace s2 {
    using s1::m;
}
int main() {
    using s1::m;
    using s2::m;
}

It compiles fine without any errors on clang (See live demo here) & MSVC++ 2015 (See live demo here) but fails in compilation on g++ 5.3.0. (See live demo here). It gives following error message:

prog.cc: In function 'int main()':
prog.cc:9:12: error: redeclaration of 'int s1::m'
  using s2::m;
            ^
prog.cc:2:6: note: previous declaration 'int s1::m'
  int m;

So, the question here is which compiler is right here according to standard? Is g++ incorrect here & is it g++'s bug ?

Aucun commentaire:

Enregistrer un commentaire