joboccara / NamedType

Implementation of strong types in C++
MIT License
773 stars 85 forks source link

`std::is_constructible` won't compile when `MethodCallable` skill added to NamedType in variant #29

Closed studoot closed 4 years ago

studoot commented 5 years ago

Consider the following code:

#include <variant>
#include <type_traits>

#include <named_type.hpp>

using test1_t = fluent::NamedType<std::string, struct test_tag, fluent::FunctionCallable>;
using test2_t = fluent::NamedType<std::string, struct test_tag, fluent::MethodCallable>;
using var1_t = std::variant<int, test1_t>;
using var2_t = std::variant<int, test2_t>;

static_assert(std::is_constructible_v<test1_t, std::string>);
static_assert(std::is_constructible_v<var1_t>);
static_assert(std::is_constructible_v<test2_t, std::string>);
static_assert(std::is_constructible_v<var2_t>);

This fails (with gcc 8.3.0, clang 8.0.0 on Ubuntu 18.04), raising the following error as a result of compiling the last line:

externals/named-type/underlying_functionalities.hpp:116:6: error: 'operator->' declared as a pointer to a reference of type 'std::__cxx11::basic_string<char, std::char_traits<char>,     
      std::allocator<char> > &'
    T* operator->() { return std::addressof(this->underlying().get()); }

The full logs are attached - clang.log, gcc.log.

I'm wondering if maybe a remove_cvref is needed somewhere, is this a variant issue or is this an expected error?

joboccara commented 4 years ago

This should have been fixed by a recent commit. I've tested the head and this code now compiles ok on gcc 8.3 and clang 8.0.0. Closing the issue, don't hesitate to reopen if that doesn't work on your end.