Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ if(XYZ_PROTOCOL_IS_NOT_SUBPROJECT)
FILES
protocol.h
protocol_reflection.hxx
interface_A.h
protocol_reflection_smoke_test.cc)
target_compile_options(protocol_reflection_smoke_test
PRIVATE -freflection)
Expand Down
25 changes: 25 additions & 0 deletions protocol_reflection_smoke_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string_view>
#include <type_traits>

#include "interface_A.h"
#include "protocol.h"

namespace {
Expand Down Expand Up @@ -66,4 +67,28 @@ TEST(ProtocolReflectionSmoke, NonConformingTypeFailsToCompile) {
std::in_place_type_t<NotAGreeter>>);
}

// name() is const and noexcept; count() is not. The vtable already erases
// every entry through void* uniformly regardless of member constness, so
// this proves mixed const/non-const dispatch works.
struct ALike {
std::string name_ = "ALike";
int count_ = 0;

std::string_view name() const noexcept { return name_; }

int count() { return ++count_; }
};

TEST(ProtocolReflectionSmoke, DispatchesBothConstAndNonConstMembersOfA) {
xyz::protocol<xyz::A> a(std::in_place_type<ALike>);
EXPECT_EQ(a.name(), "ALike");
EXPECT_EQ(a.count(), 1);
EXPECT_EQ(a.count(), 2);
}

TEST(ProtocolReflectionSmoke, ANameIsActuallyNoexcept) {
xyz::protocol<xyz::A> a(std::in_place_type<ALike>);
static_assert(noexcept(a.name()));
}

} // namespace
Loading