Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22093

Gcc vs clang difference in qualified class member lookup within template

$
0
0

The following code produces different results when compiled using gcc 14.2 or clang 19.1:

namespace mylib {    template <typename Type> void Function(const Type& t) {        // Note: explicit Type:: qualification        t.Type::Foo();    }}class Type {    public:        void Foo() const {            std::cout << "Base function";        }};class DerivedType: public Type {    public:        void Foo() const {            std::cout << "Derived function";        }};int main() {    mylib::Function(DerivedType{});}
  • in gcc 14.2: DerivedType::Foo() is called.
  • in clang 19.1: Type::Foo() is called.

Any idea which behavior should be considered correct, if any?

Note: the two compilers produce the same output if class Type is renamed to something different from the Function template argument, in which case DerivedType::Foo is called also by clang.


Viewing all articles
Browse latest Browse all 22093

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>