mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
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.
This commit is contained in:
parent
2030a49a1e
commit
ff0c7da75d
3 changed files with 17 additions and 3 deletions
|
@ -30,10 +30,14 @@
|
||||||
|
|
||||||
namespace AK::Concepts {
|
namespace AK::Concepts {
|
||||||
|
|
||||||
|
#if defined(__cpp_concepts) && !defined(__COVERITY__)
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept Integral = IsIntegral<T>::value;
|
concept Integral = IsIntegral<T>::value;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept FloatingPoint = IsFloatingPoint<T>::value;
|
concept FloatingPoint = IsFloatingPoint<T>::value;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
10
AK/Stream.h
10
AK/Stream.h
|
@ -62,7 +62,11 @@ public:
|
||||||
virtual bool discard_or_error(size_t count) = 0;
|
virtual bool discard_or_error(size_t count) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(__cpp_concepts) && !defined(__COVERITY__)
|
||||||
template<Concepts::Integral Integral>
|
template<Concepts::Integral Integral>
|
||||||
|
#else
|
||||||
|
template<typename Integral, typename EnableIf<IsIntegral<Integral>::value, int>::Type = 0>
|
||||||
|
#endif
|
||||||
InputStream& operator>>(InputStream& stream, Integral& value)
|
InputStream& operator>>(InputStream& stream, Integral& value)
|
||||||
{
|
{
|
||||||
stream.read_or_error({ &value, sizeof(value) });
|
stream.read_or_error({ &value, sizeof(value) });
|
||||||
|
@ -70,12 +74,18 @@ InputStream& operator>>(InputStream& stream, Integral& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
|
|
||||||
|
#if defined(__cpp_concepts) && !defined(__COVERITY__)
|
||||||
template<Concepts::FloatingPoint FloatingPoint>
|
template<Concepts::FloatingPoint FloatingPoint>
|
||||||
|
#else
|
||||||
|
template<typename FloatingPoint, typename EnableIf<IsFloatingPoint<FloatingPoint>::value, int>::Type = 0>
|
||||||
|
#endif
|
||||||
InputStream& operator>>(InputStream& stream, FloatingPoint& value)
|
InputStream& operator>>(InputStream& stream, FloatingPoint& value)
|
||||||
{
|
{
|
||||||
stream.read_or_error({ &value, sizeof(value) });
|
stream.read_or_error({ &value, sizeof(value) });
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline InputStream& operator>>(InputStream& stream, bool& value)
|
inline InputStream& operator>>(InputStream& stream, bool& value)
|
||||||
|
|
|
@ -33,12 +33,12 @@ namespace AK {
|
||||||
|
|
||||||
// HACK: This is just here to make syntax highlighting work in Qt Creator.
|
// HACK: This is just here to make syntax highlighting work in Qt Creator.
|
||||||
// Once it supports C++20 concepts, we can remove this.
|
// Once it supports C++20 concepts, we can remove this.
|
||||||
#ifdef __clang__
|
#if defined(__cpp_concepts) && !defined(__COVERITY__)
|
||||||
template<typename T>
|
|
||||||
#else
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept PointerTypeName = IsPointer<T>::value;
|
concept PointerTypeName = IsPointer<T>::value;
|
||||||
template<PointerTypeName T>
|
template<PointerTypeName T>
|
||||||
|
#else
|
||||||
|
template<typename T, typename EnableIf<IsPointer<T>::value, int>::Type = 0>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Userspace {
|
class Userspace {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue