Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

__func__ in template class

Shahzad_Malik_MUZAFF
558 Views

Hi,

  while trying to compile following code using "icc compiler 15.0.0", I am getting this error

>cat foo.cc
class LogDebug
{
  public:
    template< class T > LogDebug &operator<< (T const&) { return *this; }
};
class TestA {
  public:
   TestA(){LogDebug() <<__func__;}
};
template<class T>
class TestB {
  public:
   TestB(){LogDebug() <<__func__;}
};
template class TestB<int>;
>icpc -v
icpc version 15.0.0 (gcc version 4.7.2 compatibility)
>icpc -c -std=c++0x -o foo.o foo.cc
foo.cc(15): error: no operator "<<" matches these operands
            operand types are: LogDebug << const char [18]
     TestB(){LogDebug() <<__func__;}
                        ^
          detected during instantiation of "TestB<T>::TestB() [with T=int]" at line 18

compilation aborted for foo.cc (code 2)

If I drop the -std=c++0x flag then it compiles but then most of our other code does not compile. Any idea what is wrong here?

0 Kudos
6 Replies
TimP
Honored Contributor III
558 Views

I would have thought -std=c++11 would be more likely to work with g++ 4.7 or later on PATH.

The version of 15.0 update 1 which I tried first supports the gcc version compatibility flag only up to 460, and when I set that and std=c++11, I get ICE on your case.  Without the gcc compatibility flag, this compilation completed without remark.

I guess I'll submit a ticket, since that used to be the preferred way to discuss beta compilers.

0 Kudos
QIAOMIN_Q_
New Contributor I
558 Views

Hello Malik,

I have reproduced as you said ,and have entered this issue into our problem-tracking database.Thank you for submitting the issue.I'll get this posted whenever I have an update from development team.


Thank you.
--
QIAOMIN.Q
Intel Developer Support

Please participate in our redesigned community support web site:
Tools Knowledge Base:           http://software.intel.com/en-us/articles/tools

0 Kudos
Shahzad_Malik_MUZAFF
558 Views

thanks

0 Kudos
TimP
Honored Contributor III
558 Views

Qiaomin marked the issue as resolved and closed with the "latest" compiler release.  He wasn't specific about whether this means 14.0 update or 15.0 release, or both, nor about the fix (does gcc version compatibility work when a recent gcc version is specified?).

0 Kudos
QIAOMIN_Q_
New Contributor I
558 Views

Hello Timp,

I have verified that this compiles fine with the new ICC versions

$ icpc -c -std=c++0x -o foo.o foo.cc                               //ok

$ icc -v
icc version 15.0.0 (gcc version 4.4.6 compatibility)
$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.0.090 Build 20140723
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.
 

Thank you.
--
QIAOMINQ.
Intel Developer Support

 

0 Kudos
Shahzad_Malik_MUZAFF
558 Views

Thanks a lot, I will give it a try once we have the new version available.

0 Kudos
Reply