[cfe-dev] Clang issue MinGW STL alloc_traits.h error: in-class initializer for static data member is not a constant expression

Richard Smith richard at metafoo.co.uk
Sun Jun 23 23:49:47 PDT 2013


On Sun, Jun 23, 2013 at 11:38 PM, Kim <soldoutseashell at gmail.com> wrote:
>>What is _S_chk?
>
> _S_chk is a member function from a class in alloc_traits.h
>
>   template<typename _Alloc, typename _Tp>
>     class __alloctr_rebind_helper
>     {
>       template<typename _Alloc2, typename _Tp2>
>     static constexpr bool
>            _S_chk(typename _Alloc2::template rebind<_Tp2>::other*)
>     { return true; }
>
>       template<typename, typename>
>         static constexpr bool
>            _S_chk(...)
>            { return false; }
>
>     public:
>
>     static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);
>     };

OK, this is llvm.org/PR15651. Essentially, -fdelayed-template-parsing
(which is enabled by default on some Windows targets) is currently
incompatible with constexpr. -fno-delayed-template-parsing will
probably help (if it doesn't cause breakage in other headers). I
wonder if we should stop enabling -fno-delayed-template-parsing by
default on MinGW -- MinGW's gcc presumably doesn't behave that way.

>
> bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value
>
> constexpr - specifies that the value of a variable or function can be
> computed at compile time
>
> I don't understand this part here (the usage of rebind), I'll need to read
> into it later:
>
> typename _Alloc2::template rebind<_Tp2>::other*
>
> But I found an explanation here
> (http://cboard.cprogramming.com/tech-board/156319-anyone-gotten-clank-work-windows.html)
>
> "For some reason, it doesn't recognize the constexpr call _S_chk<_Alloc,
> _Tp>(nullptr) as constant, which causes an error. This error is triggered
> ultimately from vector's attempt to rebind the allocator you passed to the
> type you passed (to protect itself from stupid people writing vector<double,
> allocator<int>>). So allocator_traits<Alloc>::rebind<double>: ther fails to
> instantiate, and the compiler attempts to recover by making the result int
> and moving on. But now vector uses 'int' as its allocator type, which causes
> all sorts of errors when it subsequently attempts to access allocator's
> various nested types."
>
>
>
>
> On 2013/06/24 12:55, Richard Smith wrote:
>
> On Sun, Jun 23, 2013 at 9:15 PM, Kim <soldoutseashell at gmail.com> wrote:
>
> I'm getting this error while trying to compile code including MinGW STL
> headers with clang, I'm wondering if perhaps mingw's headers aren't fully
> supported in the latest version or if (more likely) I'm missing some
> important arguments. I'm using clang built using visual studio 11 with
> disabled inbuilt directories. Should I downgrade to an earlier
> version/combination of mingw and clang that is confirmed to work well? I've
> also tried the visual studio headers but I was told many features won't work
> (yet).
>
> Perhaps if someone is successfully compiling code on win with clang that
> uses the mingw headers they could share the complete set of arguments they
> are using. Would be much appreciated.
>
> Thanks very much in advance.
>
>
> Simple.cpp:
>
> #include <vector>
> #include <map>
>
> int main()
> {
>      return 0;
> }
>
>
> Output
> ==================================================================================
>
> C:\Program Files (x86)\LLVM\vs11\bin\Debug>clang++ -fno-ms-compatibility
> -nostdinc -std=c++11 -c -v -o simple.o simple.cpp -I "C:\MinGW\include\sys"
> -I "C:\MinGW\lib\gcc\i686-pc-mingw32\4.8.0\include" -I "C:\MinGW\include" -I
> "C:\MinGW\include\c++" -I "C:\MinGW\include\c++\4.8.0" -I
> "C:\MinGW\include\c++\4.8.0\backward" -I "C:\MinGW\include\c++\4.8.0\bits"
> -I "C:\MinGW\include\c++\4.8.0\debug" -I
> "C:\MinGW\include\c++\4.8.0\decimal" -I "C:\MinGW\include\c++\4.8.0\ext" -I
> "C:\MinGW\include\c++\4.8.0\i686-pc-mingw32" -I
> "C:\MinGW\include\c++\4.8.0\tr1" -I "C:\MinGW\include\c++\4.8.0\tr2" -I
> "C:\MinGW\include\c++\4.8.0\profile"
> clang version 3.4 (trunk)
> Target: i686-pc-win32
> Thread model: posix
>  "C:/Program Files (x86)/LLVM/vs11/bin/Debug/clang++.exe" -cc1 -triple
> i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name simple.cpp
> -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
> -mconstructor-aliases -target-cpu pentium4 -v -coverage-file simple.o
> -nostdsysteminc -nobuiltininc -resource-dir "C:/Program Files
> (x86)/LLVM/vs11/bin/Debug\\..\\lib\\clang\\3.4" -I "C:\\MinGW\\include\\sys"
> -I "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.8.0\\include" -I
> "C:\\MinGW\\include" -I "C:\\MinGW\\include\\c++" -I
> "C:\\MinGW\\include\\c++\\4.8.0" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\backward" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\bits" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\debug" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\decimal" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\ext" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\i686-pc-mingw32" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\tr1" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\tr2" -I
> "C:\\MinGW\\include\\c++\\4.8.0\\profile" -std=c++11 -fdeprecated-macro
> -ferror-limit 19 -fmessage-length 150 -mstackrealign -fms-extensions
> -fmsc-version=1300 -fdelayed-template-parsing -fobjc-runtime=gcc
> -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions
> -fdiagnostics-show-option -fcolor-diagnostics -backend-option
> -vectorize-loops -o simple.o -x c++ simple.cpp
> clang -cc1 version 3.4 based upon LLVM 3.4svn default target i686-pc-win32
> #include "..." search starts here:
> #include <...> search starts here:
>  C:\MinGW\include\sys
>  C:\MinGW\lib\gcc\i686-pc-mingw32\4.8.0\include
>  C:\MinGW\include
>  C:\MinGW\include\c++
>  C:\MinGW\include\c++\4.8.0
>  C:\MinGW\include\c++\4.8.0\backward
>  C:\MinGW\include\c++\4.8.0\bits
>  C:\MinGW\include\c++\4.8.0\debug
>  C:\MinGW\include\c++\4.8.0\decimal
>  C:\MinGW\include\c++\4.8.0\ext
>  C:\MinGW\include\c++\4.8.0\i686-pc-mingw32
>  C:\MinGW\include\c++\4.8.0\tr1
>  C:\MinGW\include\c++\4.8.0\tr2
>  C:\MinGW\include\c++\4.8.0\profile
> End of search list.
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:62:
> In file included from C:\MinGW\include\c++\4.8.0\bits/stl_construct.h:61:
> In file included from C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:36:
> C:\MinGW\include\c++\4.8.0\bits/alloc_traits.h:57:31: error: in-class
> initializer for static data member is not a constant expression
>                 static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> What is _S_chk?
>
> C:\MinGW\include\c++\4.8.0\bits/alloc_traits.h:64:19: note: in instantiation
> of template class
>       'std::__alloctr_rebind_helper<std::allocator<int>, int>' requested
> here
>            bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
>                   ^
> C:\MinGW\include\c++\4.8.0\bits/alloc_traits.h:202:9: note: in instantiation
> of default argument for '__alloctr_rebind<std::allocator<int>, int>'
>       required here
>         using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type;
>         ^~~~~
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:196:47: note: in instantiation
> of template type alias 'rebind_alloc' requested here
>       { typedef typename _Base_type::template rebind_alloc<_Tp> other; };
>                                               ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:74:59: note: in instantiation
> of template class '__gnu_cxx::__alloc_traits<std::allocator<int>
>       >::rebind<int>' requested here
>       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
>                                                           ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:210:30: note: in instantiation
> of template class 'std::_Vector_base<int, std::allocator<int> >' requested
>       here
>     class vector : protected _Vector_base<_Tp, _Alloc>
>                              ^
> simple.cpp:7:19: note: in instantiation of template class 'std::vector<int,
> std::allocator<int> >' requested here
>         std::vector<int> test;
>                          ^
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:62:
> In file included from C:\MinGW\include\c++\4.8.0\bits/stl_construct.h:61:
> In file included from C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:36:
> C:\MinGW\include\c++\4.8.0\bits/alloc_traits.h:90:24: error: type 'int'
> cannot be used prior to '::' because it has no members
>       typedef typename _Alloc::value_type value_type;
>                        ^
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:123:5: note: in instantiation
> of template class 'std::allocator_traits<int>' requested here
>   : std::allocator_traits<_Alloc>
>     ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:76:35: note: in instantiation
> of template class '__gnu_cxx::__alloc_traits<int>' requested here
>       typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
>                                   ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:210:30: note: in instantiation
> of template class 'std::_Vector_base<int, std::allocator<int> >' requested
>       here
>     class vector : protected _Vector_base<_Tp, _Alloc>
>                              ^
> simple.cpp:7:19: note: in instantiation of template class 'std::vector<int,
> std::allocator<int> >' requested here
>         std::vector<int> test;
>                          ^
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:62:
> In file included from C:\MinGW\include\c++\4.8.0\bits/stl_construct.h:61:
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:137:11: error: using
> declaration refers into '_Base_type::', which is not a base class of
>       '__alloc_traits<int>'
>     using _Base_type::allocate;
>           ^~~~~~~~~~~~
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:76:35: note: in instantiation
> of template class '__gnu_cxx::__alloc_traits<int>' requested here
>       typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer
>                                   ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:210:30: note: in instantiation
> of template class 'std::_Vector_base<int, std::allocator<int> >' requested
>       here
>     class vector : protected _Vector_base<_Tp, _Alloc>
>                              ^
> simple.cpp:7:19: note: in instantiation of template class 'std::vector<int,
> std::allocator<int> >' requested here
>         std::vector<int> test;
>                          ^
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:62:
> In file included from C:\MinGW\include\c++\4.8.0\bits/stl_construct.h:61:
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:138:11: error: using
> declaration refers into '_Base_type::', which is not a base class of
>       '__alloc_traits<int>'
>     using _Base_type::deallocate;
>           ^~~~~~~~~~~~
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:139:11: error: using
> declaration refers into '_Base_type::', which is not a base class of
>       '__alloc_traits<int>'
>     using _Base_type::construct;
>           ^~~~~~~~~~~~
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:140:11: error: using
> declaration refers into '_Base_type::', which is not a base class of
>       '__alloc_traits<int>'
>     using _Base_type::destroy;
>           ^~~~~~~~~~~~
> C:\MinGW\include\c++\4.8.0\ext/alloc_traits.h:141:11: error: using
> declaration refers into '_Base_type::', which is not a base class of
>       '__alloc_traits<int>'
>     using _Base_type::max_size;
>           ^~~~~~~~~~~~
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:64:
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:80:16: error: base specifier
> must name a class
>       : public _Tp_alloc_type
>         ~~~~~~~^~~~~~~~~~~~~~
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:164:20: note: in instantiation
> of member class 'std::_Vector_base<int, std::allocator<int>
>       >::_Vector_impl' requested here
>       _Vector_impl _M_impl;
>                    ^
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:210:30: note: in instantiation
> of template class 'std::_Vector_base<int, std::allocator<int> >' requested
>       here
>     class vector : protected _Vector_base<_Tp, _Alloc>
>                              ^
> simple.cpp:7:19: note: in instantiation of template class 'std::vector<int,
> std::allocator<int> >' requested here
>         std::vector<int> test;
>                          ^
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:64:
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:237:13: error: using
> declaration refers into '_Base::', which is not a base class of
>       'vector<int, std::allocator<int> >'
>       using _Base::_M_allocate;
>             ^~~~~~~
> simple.cpp:7:19: note: in instantiation of template class 'std::vector<int,
> std::allocator<int> >' requested here
>         std::vector<int> test;
>                          ^
> In file included from simple.cpp:2:
> In file included from C:\MinGW\include\c++\4.8.0\vector:64:
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:238:13: error: using
> declaration refers into '_Base::', which is not a base class of
>       'vector<int, std::allocator<int> >'
>       using _Base::_M_deallocate;
>             ^~~~~~~
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:239:13: error: using
> declaration refers into '_Base::', which is not a base class of
>       'vector<int, std::allocator<int> >'
>       using _Base::_M_impl;
>             ^~~~~~~
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:240:13: error: using
> declaration refers into '_Base::', which is not a base class of
>       'vector<int, std::allocator<int> >'
>       using _Base::_M_get_Tp_allocator;
>             ^~~~~~~
> C:\MinGW\include\c++\4.8.0\bits/stl_vector.h:529:13: error: using
> declaration refers into '_Base::', which is not a base class of
>       'vector<int, std::allocator<int> >'
>       using _Base::get_allocator;
>             ^~~~~~~
> 13 errors generated.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>



More information about the cfe-dev mailing list