PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Reproduce non-standard template name lookup

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
dchubarov



Joined: 08 Apr 2010
Posts: 1

PostPosted: Mon Jun 18, 2012 10:44 am    Post subject: Reproduce non-standard template name lookup Reply with quote

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:

Code:
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:

Code:
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.
Back to top
View user's profile
Deborah Caruso



Joined: 20 Oct 2004
Posts: 43

PostPosted: Mon Jun 18, 2012 4:58 pm    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group