0
namespace fooo {
  class Fooo {
  public:
    int a;
  };
}

namespace fooo {
  class Test {
  public:
    Test(Fooo::Fooo *i) {
      i->a = 1;
    }
  };
}

This code compiles fine with clang (any version) but fails with gcc. Can anyone explain why?

EDIT: Yes, I know the issue here is kinda obvious but why does clang accept it? The person who told me this said that this is a bug in the standard and that there is a Defect Report. Can anyone point to the actual DR?

lled
  • 61
  • 1
  • 4
  • 1
    Didn't gcc tell you? It usually shows a diagnostic message if compilation fails. – eerorika May 27 '16 at 21:57
  • error: ‘fooo::Fooo::Fooo’ names the constructor, not the type –  May 27 '16 at 21:59
  • Even if the first Fooo is a typo: error: assignment of member ‘fooo::Fooo::a’ in read-only object –  May 27 '16 at 22:00
  • Ah, that's that old class name injected in class definition thing. Usually, clang is wrong in this iirc, but I don't remember the specifics. Let me see if I can find a dupe. – Baum mit Augen May 27 '16 at 22:00
  • Sorry, I removed the const. – lled May 27 '16 at 22:01
  • Yes I know the issue here but why does clang accept it? The person who told me this said that this is an bug in the standard and that there is a Defect Report. – lled May 27 '16 at 22:03
  • Yep, unfixed clang bug indeed. There are links to existing bug reports in the dupe answer. – Baum mit Augen May 27 '16 at 22:03
  • @Edit: Read the answers in the dupe, there are links to the clang bugs and to the defect report. – Baum mit Augen May 27 '16 at 22:08

1 Answers1

0

The error message from gcc tells you exactly what the problem is:

t.cpp:11:16: error: ‘fooo::Fooo::Fooo’ names the constructor, not the type
     Test(const Fooo::Fooo *i) {
                ^

it is suprising that clang doesn't give an error.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226