Skip to content

Commit ff0c7da

Browse files
bgianfoawesomekling
authored andcommitted
AK: Add SFINAE fallback for AK C++ concepts use, for Coverity compiler
The Coverity compiler doesn't support C++2a yet, and thus doesn't even recognize concept keywords. To allow serenity to be built and analyzed on such compilers, add a fallback underdef to perform the same template restriction based on AK::EnableIf<..> meta programming. Note: Coverity does seem to (annoyingly) define __cpp_concepts, even though it doesn't support them, so we need to further check for __COVERITY__ explicitly.
1 parent 2030a49 commit ff0c7da

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

AK/Concepts.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@
3030

3131
namespace AK::Concepts {
3232

33+
#if defined(__cpp_concepts) && !defined(__COVERITY__)
34+
3335
template<typename T>
3436
concept Integral = IsIntegral<T>::value;
3537

3638
template<typename T>
3739
concept FloatingPoint = IsFloatingPoint<T>::value;
3840

41+
#endif
42+
3943
}

AK/Stream.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,30 @@ class InputStream : public AK::Detail::Stream {
6262
virtual bool discard_or_error(size_t count) = 0;
6363
};
6464

65+
#if defined(__cpp_concepts) && !defined(__COVERITY__)
6566
template<Concepts::Integral Integral>
67+
#else
68+
template<typename Integral, typename EnableIf<IsIntegral<Integral>::value, int>::Type = 0>
69+
#endif
6670
InputStream& operator>>(InputStream& stream, Integral& value)
6771
{
6872
stream.read_or_error({ &value, sizeof(value) });
6973
return stream;
7074
}
7175

7276
#ifndef KERNEL
77+
78+
#if defined(__cpp_concepts) && !defined(__COVERITY__)
7379
template<Concepts::FloatingPoint FloatingPoint>
80+
#else
81+
template<typename FloatingPoint, typename EnableIf<IsFloatingPoint<FloatingPoint>::value, int>::Type = 0>
82+
#endif
7483
InputStream& operator>>(InputStream& stream, FloatingPoint& value)
7584
{
7685
stream.read_or_error({ &value, sizeof(value) });
7786
return stream;
7887
}
88+
7989
#endif
8090

8191
inline InputStream& operator>>(InputStream& stream, bool& value)

AK/Userspace.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ namespace AK {
3333

3434
// HACK: This is just here to make syntax highlighting work in Qt Creator.
3535
// Once it supports C++20 concepts, we can remove this.
36-
#ifdef __clang__
37-
template<typename T>
38-
#else
36+
#if defined(__cpp_concepts) && !defined(__COVERITY__)
3937
template<typename T>
4038
concept PointerTypeName = IsPointer<T>::value;
4139
template<PointerTypeName T>
40+
#else
41+
template<typename T, typename EnableIf<IsPointer<T>::value, int>::Type = 0>
4242
#endif
4343

4444
class Userspace {

0 commit comments

Comments
 (0)