Given that cppcheck has to compile with a variety of C++ compilers, I'd be tempted to rework the cppcheck code into something most C++ compilers can easily accept.
Writing bleeding edge C++ code that some compilers have trouble implementing is IMHO asking for trouble.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Given that cppcheck has to compile with a variety of C++ compilers, I'd be tempted to rework the cppcheck code into something most C++ compilers can easily accept.
As far as I know that is our approach. Do you see some bleeding edge C++ code?
According to the PR the problem is the opposite.. bleeding edge libraries require some attribute that we don't have?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, use of lambdas. They have only been around since C++11 and have been enhanced
ever since (C++14, C++17). That's probably ok if cppcheck only had to work with one compiler.
I'd be interested to find out which C++ compiler accepts the current cppcheck code.
MS maybe ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We do require some C++11 features. I do not think there is C++14 or later features. You can compile cppcheck source code with g++ 4.8 so the problem is not that we are too bleeding edge.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Fedora 38 has been released with new gcc-13. Some newish C++ syntax
for lambdas in the source code of cppcheck doesn't compile.
/usr/include/c++/13/bits/alloc_traits.h: In instantiation of ‘struct std::__allocator_traits_base::__rebind<taggedallocator\<referencetoken, 3="">, ReferenceToken, void>’:
/usr/include/c++/13/bits/alloc_traits.h:94:11: required by substitution of ‘template<class _alloc,="" class="" _up=""> using std::__alloc_rebind = typename std::__allocator_traits_base::__rebind<_Alloc, _Up>::type [with _Alloc = TaggedAllocator<referencetoken, 3="">; _Up = ReferenceToken]</referencetoken,>’
/usr/include/c++/13/bits/alloc_traits.h:228:8: required by substitution of ‘template<class _alloc=""> template<class _tp=""> using std::allocator_traits< <template-parameter-1-1> >::rebind_alloc = std::__alloc_rebind<_Alloc, _Tp> [with _Tp = ReferenceToken; _Alloc = TaggedAllocator<referencetoken, 3="">]</referencetoken,>’
/usr/include/c++/13/ext/alloc_traits.h:126:65: required from ‘struct __gnu_cxx::__alloc_traits<taggedallocator\<referencetoken, 3="">, ReferenceToken>::rebind<referencetoken>’
/usr/include/c++/13/bits/stl_vector.h:88:21: required from ‘struct std::_Vector_base<referencetoken, taggedallocator\<referencetoken,="" 3=""> >’
/usr/include/c++/13/bits/stl_vector.h:423:11: required from ‘class std::vector<referencetoken, taggedallocator\<referencetoken,="" 3=""> >’
lib/smallvector.h:47:7: required from ‘class SmallVector<referencetoken>’
lib/astutils.cpp:1158:58: required from here
/usr/include/c++/13/bits/alloc_traits.h:70:31: error: static assertion failed: allocator_traits::rebind_alloc<a::value_type> must be A
70 | _Tp>::value,
| ^~~~~</a::value_type></referencetoken></referencetoken,></referencetoken,></referencetoken></taggedallocator\<referencetoken,></template-parameter-1-1></class></class></class></taggedallocator\<referencetoken,>
I also tried clang++ version 16.0.2 and that didn't like the source code either:
In file included from lib/astutils.h:26:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/stack:62:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/deque:65:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/stl_uninitialized.h:64:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/ext/alloc_traits.h:34:
/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:68:2: error: static assertion failed due to requirement 'is_same<std::allocator\<referencetoken>, TaggedAlloc ator\<referencetoken, 3="">>::value': allocator_traits</referencetoken,></std::allocator\<referencetoken>::rebind_alloc<a::value_type> must be A
static_assert(is_same<
^ ~~~~~~~~
/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:94:5: note: in instantiation of template class 'std::__allocator_traits_base::__rebind<taggedallocator\<refer encetoken,="" 3="">, ReferenceToken>' requested here
using __alloc_rebind
^</taggedallocator\<refer></a::value_type>
If someone would finish this PR... https://github.com/danmar/cppcheck/pull/5015/
Thanks for the information.
Given that cppcheck has to compile with a variety of C++ compilers, I'd be tempted to rework the cppcheck code into something most C++ compilers can easily accept.
Writing bleeding edge C++ code that some compilers have trouble implementing is IMHO asking for trouble.
As far as I know that is our approach. Do you see some bleeding edge C++ code?
According to the PR the problem is the opposite.. bleeding edge libraries require some attribute that we don't have?
Yes, use of lambdas. They have only been around since C++11 and have been enhanced
ever since (C++14, C++17). That's probably ok if cppcheck only had to work with one compiler.
I'd be interested to find out which C++ compiler accepts the current cppcheck code.
MS maybe ?
We do require some C++11 features. I do not think there is C++14 or later features. You can compile cppcheck source code with g++ 4.8 so the problem is not that we are too bleeding edge.
C++11 lambdas is something we do require.
Two workarounds:
The static assert went into gcc trunk on 2022-12-14, so use a compiler from before then.
20221204 seems to work.
More brutally, remove the static assert from the alloc_traits.h header file.
This will affect other builds.
have you tried to apply the changes in PR 5015?
https://github.com/danmar/cppcheck/pull/5015/files
Yes and the changes make it work for both gcc and clang. Thanks very much !
Some warnings were produced, I will make those the subject of another thread.