0
template <typename T>
class Foo{
    private:
        class Bar{            
        };
};

template <typename T>
void Fun(const Foo<T> &f){
    Foo<int>::Bar b;  //This line of code.
}

int main(){
    Foo<int> f;
    Fun(f);
    return 0;
}

g++ can compile it with no error while Clang points out that Foo<int>::Bar is inaccessiable.

g++: https://wandbox.org/permlink/9scQUmfVLQU6IM0J
Clang: https://wandbox.org/permlink/dQm9VcsZURbjxrFZ

What's wrong with g++? I trusted it so much. Should I use Clang for learning instead?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Rick
  • 7,007
  • 2
  • 49
  • 79
  • 1
    `Foo::Bar b;` Looks weird to appear in a generalized template. – πάντα ῥεῖ Oct 22 '18 at 19:35
  • @drescherjm g++ only gives *unused variables* warnings. – Rick Oct 22 '18 at 19:37
  • Umm... You can use both? – StoryTeller - Unslander Monica Oct 22 '18 at 19:37
  • Compilers have bugs. It's just the nature of the game, especially considering how complex the C++ language is. This's shouldn't force you to change compilers though. – NathanOliver Oct 22 '18 at 19:39
  • @πάνταῥεῖ Here's the situation. I was writing some code and changed a nested class as `private`. I was thinking the IDE(it uses g++) should gives a error. But it didn't. So I was thinking that I might be wrong. Then I tried on Clang, I felt untrusted on g++. – Rick Oct 22 '18 at 19:39
  • @NathanOliver Yes.. But I am always told that *remember that compilers are way much smarter than you*. Since I am still learning, so sometimes I memory what the compiler gives me back. – Rick Oct 22 '18 at 19:42
  • removing the template on Fun gives the expected error https://wandbox.org/permlink/9scQUmfVLQU6IM0J – OznOg Oct 22 '18 at 19:48
  • @NathanOliver Ok. Please mark it as duplicated or I can delete it direclty. Maybe next time I shouldn't ask this kind of question. It's not helpful after all. – Rick Oct 22 '18 at 19:50
  • I've closed it as a dupe. If you want to delete it you can. – NathanOliver Oct 22 '18 at 19:51

0 Answers0