最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Error with redefinition within inline namespace using devtoolset compiler - Stack Overflow

programmeradmin6浏览0评论

I'm facing a strange error in compiling a C++ 3rd party software under CentOS 7 with devtoolset-11. The situation can be summarized in this code snippet:

#include <list>
namespace std{
  #ifdef _GLIBCXX_USE_CXX11_ABI
   #pragma message("Redefining list")
   inline namespace __cxx11 {
     template<class elem, class alloc> class list;
   }
  #endif
}


int main(){
        std::list<int> l;
        return 0;
}

(please don't ask me details about the meaning of the above or suggest me to modify it: it's just a reproducer of an issue occurring in a more complicate code base which I don't fully master, and its only purpose is to trigger the error described in the following).

Compiling with devtoolset-11 C++ compiler under CentOS 7 I get this error:

test.cpp:4:37: note: '#pragma message: Redefining list'
    4 |    #pragma message("Redefining list")
      |                                     ^
test.cpp: In function 'int main()':
test.cpp:13:14: error: reference to 'list' is ambiguous
   13 |         std::list<int> l;
      |              ^~~~
test.cpp:6:46: note: candidates are: 'template<class elem, class alloc> class std::__cxx11::list'
    6 |      template<class elem, class alloc> class list;
      |                                              ^~~~
In file included from /opt/rh/devtoolset-11/root/usr/include/c++/11/list:63,
                 from test.cpp:1:
/opt/rh/devtoolset-11/root/usr/include/c++/11/bits/stl_list.h:556:11: note:                 'template<class _Tp, class _Alloc> class std::list'
  556 |     class list : protected _List_base<_Tp, _Alloc>
      |           ^~~~
test.cpp:13:19: error: expected primary-expression before 'int'
   13 |         std::list<int> l;
      |                   ^~~

What I don't understand is that compiling the very same code snippet under AlmaLinux 9 with the native g++ 11 compiler I don't get any error. I did several tests with different compiler versions (also on Compiler Explorer) and different devtoolset versions (7, 8 and 11) under CentOS 7, and I found that the error occurs only with devtoolset.

I cannot figure out what feature of devtoolset might generate this problem and how to fix it. Any help is greatly appreciated.

发布评论

评论列表(0)

  1. 暂无评论