Reproduce non-standard template name lookup

It is sometimes useful to be able to reproduce non-standard behavior of other compilers. That is when strict standards compliance can break a lot of legacy code that was only tested with the permissive compilers.

C++ standard is notoriously difficult to comply. With PGI I use -A option to check if the code is non-compliant. Without -A PGI compiler can often compile non-compliant code.

Recently I came across an issue related to the Two-phase name lookup rule in C++ template instantiation where a popular open source library (GAlib) contained code written prior to 2005 that produced compilation error with the -A option or with Clang. Yet this code compiles with a string of compilers including pre 4.7 GNU C++ and a few others. I expected PGI compiler without -A to compile that as well, but in this instance it produced the same error either with or without -A.

I reduced the code in question to the following example:

class Object {
public:
  typedef void  (*Function)(Object &);
public:
  Function set_func(Function f){return (func = f);}
protected:
  Function func;
};

template <class T>
class TemplateObject : public Object {};

template <class T>
class TemplateParam {};

template <class T>
class ParamTemplateObject : public TemplateObject<T> {
public:
  static void function(Object&){}
public:
  ParamTemplateObject(const TemplateParam<T> & p);
};

template <class T>
ParamTemplateObject<T>::
ParamTemplateObject( const TemplateParam<T> & p) :
TemplateObject<T>(){
  set_func(ParamTemplateObject<T>::function);
}

int main(){
   TemplateParam<int> p;
   ParamTemplateObject<int> a (p);
}

When compiled with pgCC ver. 11.10 it produces the following error message:

line 28: error: identifier "set_func" is undefined
    set_func(ParamTemplateObject<T>::function);
    ^

Which is correct wrt. to the two-phase name lookup rule since during template instantiation the compiler may not lookup unqualified symbols in non-template base classes.

One solution here would be to modify the code adding qualification this-> to the set_func symbol.

However I would like to know if there is an option to pgCC that would make the compiler accept this code without qualification and reproduce the behaviour of pre 4.7 GNU C++ and other permissive compilers.

We have filed flyspray 18778 to address the gnu compatibility issue with member function name lookup inside of templates.

I’m sorry to say that I have found no command line compatibility switch to address this issue.
-Deborah Caruso