Skip to content

Commit

Permalink
Fix PRINCIPIA_CHECK_ILL_FORMED in the clang build
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Apr 7, 2024
1 parent 19f5b71 commit a4b79e8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
24 changes: 16 additions & 8 deletions geometry/frame_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ class FrameTest : public testing::Test {
using FrameDeathTest = FrameTest;

// Check that non-serializable frames are detected at compile-time.
PRINCIPIA_CHECK_WELL_FORMED(FrameTest::World1::ReadFromMessage(message),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED(FrameTest::F1::ReadFromMessage(message),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED(FrameTest::F2::ReadFromMessage(message),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED(FrameTest::F3::ReadFromMessage(message),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_WELL_FORMED_WITH_TYPES(
World1::ReadFromMessage(message),
(typename World1 = FrameTest::World1),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
F1::ReadFromMessage(message),
(typename F1 = FrameTest::F1),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
F2::ReadFromMessage(message),
(typename F2 = FrameTest::F2),
with_variable<serialization::Frame> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
F3::ReadFromMessage(message),
(typename F3 = FrameTest::F3),
with_variable<serialization::Frame> message);

TEST_F(FrameDeathTest, SerializationError) {
EXPECT_DEATH({
Expand Down
23 changes: 15 additions & 8 deletions geometry/grassmann_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,22 @@ PRINCIPIA_CHECK_WELL_FORMED(v.WriteToMessage(&message),
with_variable<Trivector<Length, F>> v,
with_variable<serialization::Multivector> message);

PRINCIPIA_CHECK_WELL_FORMED(
(Vector<Length, GrassmannTest::World>::ReadFromMessage(message)),
PRINCIPIA_CHECK_WELL_FORMED_WITH_TYPES(
V::ReadFromMessage(message),
(typename V = Vector<Length, GrassmannTest::World>),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
V::ReadFromMessage(message),
(typename V = Vector<Length, F>),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
V::ReadFromMessage(message),
(typename V = Bivector<Length, F>),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(
V::ReadFromMessage(message),
(typename V = Trivector<Length, F>),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED((Vector<Length, F>::ReadFromMessage(message)),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED((Bivector<Length, F>::ReadFromMessage(message)),
with_variable<serialization::Multivector> message);
PRINCIPIA_CHECK_ILL_FORMED((Trivector<Length, F>::ReadFromMessage(message)),
with_variable<serialization::Multivector> message);

TEST_F(GrassmannDeathTest, SerializationError) {
using V = Vector<Length, World>;
Expand Down
28 changes: 27 additions & 1 deletion testing_utilities/check_well_formedness.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#pragma once

Check warning on line 1 in testing_utilities/check_well_formedness.hpp

View workflow job for this annotation

GitHub Actions / check-iwyu

Include what you using

include_what_you_using_all_the_things.ps1 modifies this file as follows: diff --git a/testing_utilities/check_well_formedness.hpp b/testing_utilities/check_well_formedness.hpp index 6c5688e..60ec1f6 100644 --- a/testing_utilities/check_well_formedness.hpp +++ b/testing_utilities/check_well_formedness.hpp @@ -1,8 +1,6 @@ #pragma once #include <type_traits> -#include "base/macros.hpp" - #define PRINCIPIA_EXPAND(...) __VA_ARGS__ #define PRINCIPIA_CONCATENATE(s1, s2) s1##s2
#include <type_traits>

#include "base/macros.hpp"

#define PRINCIPIA_EXPAND(...) __VA_ARGS__

#define PRINCIPIA_CONCATENATE(s1, s2) s1##s2
#define PRINCIPIA_CONCATENATE_EXPANSION(s1, s2) PRINCIPIA_CONCATENATE(s1, s2)

#define PRINCIPIA_COMMA_IF_NONEMPTY(...) __VA_OPT__(,)

Check warning on line 11 in testing_utilities/check_well_formedness.hpp

View workflow job for this annotation

GitHub Actions / check-cpp

whitespace/comma

Missing space after ,

#define PRINCIPIA_CHECK_WELL_FORMEDNESS(unique_concept_name, \
expected_well_formedness, \
expected_well_formedness_description, \
expression, \
types, \
...) \
template<template<typename> typename with_variable = std::type_identity_t> \
template<template<typename> typename with_variable = std::type_identity_t \
PRINCIPIA_COMMA_IF_NONEMPTY types PRINCIPIA_EXPAND types> \
concept unique_concept_name = requires(__VA_ARGS__) { (expression); }; \
static_assert(expected_well_formedness unique_concept_name<>, \
"Expected\n " #expression \
Expand All @@ -20,11 +28,29 @@
!, \
"not to compile", \
expression, \
(), \
__VA_ARGS__)
#define PRINCIPIA_CHECK_WELL_FORMED(expression, ...) \
PRINCIPIA_CHECK_WELL_FORMEDNESS( \
PRINCIPIA_CONCATENATE_EXPANSION(test_concept_, __COUNTER__), \
, \
"to compile", \
expression, \
(), \
__VA_ARGS__)
#define PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(expression, types, ...) \
PRINCIPIA_CHECK_WELL_FORMEDNESS( \
PRINCIPIA_CONCATENATE_EXPANSION(test_concept_, __COUNTER__), \
!, \
"not to compile", \
expression, \
types, \
__VA_ARGS__)
#define PRINCIPIA_CHECK_WELL_FORMED_WITH_TYPES(expression, types, ...) \
PRINCIPIA_CHECK_WELL_FORMEDNESS( \
PRINCIPIA_CONCATENATE_EXPANSION(test_concept_, __COUNTER__), \
, \
"to compile", \
expression, \
types, \
__VA_ARGS__)
2 changes: 2 additions & 0 deletions testing_utilities/check_well_formedness_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string>
#include <utility>

PRINCIPIA_CHECK_ILL_FORMED_WITH_TYPES(T::npos, (typename T = int));
PRINCIPIA_CHECK_WELL_FORMED_WITH_TYPES(T::npos, (typename T = std::string));
PRINCIPIA_CHECK_ILL_FORMED(s + 3, with_variable<std::string> s);
PRINCIPIA_CHECK_ILL_FORMED(s + "3", with_variable<std::pair<double, double>> s);
PRINCIPIA_CHECK_WELL_FORMED(s + t,
Expand Down

0 comments on commit a4b79e8

Please sign in to comment.