Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types\optional_test.cc compilation issue with Visual Studio 2017 (v15.8) #198

Open
Mizux opened this issue Oct 19, 2018 · 1 comment
Open
Labels

Comments

@Mizux
Copy link
Contributor

Mizux commented Oct 19, 2018

Description

When trying to do a CMake-based build with test of abseil-cpp, I got an compile error on
types\optional_test.cc

note: I've applied the PR #194 (absl::container similar issue?) and #196 (alignment conformance) and PR #197 (CI cmake jobs)

optional_test.cc
  Building Custom Rule C:/projects/abseil-cpp/absl/debugging/CMakeLists.txt
  exception_safety_testing.cc
  CMake does not need to re-run because C:/projects/abseil-cpp/build/absl/debugging/CMakeFiles/generate.stamp is up-to-date.
c:\projects\abseil-cpp\absl\types\optional_test.cc(1108): fatal error C1001: An internal error has occurred in the compiler. [C:\projects\abseil-cpp\build\absl\types\optional_test_bin.vcxproj]
  (compiler file 'msc1.cpp', line 1518)
   To work around this problem, try simplifying or changing the program near the locations listed above.
  Please choose the Technical Support command on the Visual C++ 
   Help menu, or open the Technical Support help file for more information
  Internal Compiler Error in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\CL.exe.  You will be prompted to send an error report to Microsoft later.

Full Appveyor-CI log line 708:
https://ci.appveyor.com/project/Mizux/abseil-cpp/builds/19632736/job/thal0yvy6dacd9e0

The code optional_test.cc in the error log:

// MSVC has a bug with "cv-qualifiers in class construction", fixed in 2017. See
// https://docs.microsoft.com/en-us/cpp/cpp-conformance-improvements-2017#bug-fixes
// The compiler some incorrectly ingores the cv-qualifier when generating a
// class object via a constructor call. For example:
//
// class optional {
// constexpr T&& value() &&;
// constexpr const T&& value() const &&;
// }
//
// using COI = const absl::optional<int>;
// static_assert(2 == COI(2).value(), ""); // const &&
//
// This should invoke the "const &&" overload but since it ignores the const
// qualifier it finds the "&&" overload the best candidate.
#if defined(_MSC_VER) && _MSC_VER < 1910
#define ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG
#endif
TEST(optionalTest, Value) {
using O = absl::optional<std::string>;
using CO = const absl::optional<std::string>;
using OC = absl::optional<const std::string>;
O lvalue(absl::in_place, "lvalue");
CO clvalue(absl::in_place, "clvalue");
OC lvalue_c(absl::in_place, "lvalue_c");
EXPECT_EQ("lvalue", lvalue.value());
EXPECT_EQ("clvalue", clvalue.value());
EXPECT_EQ("lvalue_c", lvalue_c.value());
EXPECT_EQ("xvalue", O(absl::in_place, "xvalue").value());
EXPECT_EQ("xvalue_c", OC(absl::in_place, "xvalue_c").value());
#ifndef ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG
EXPECT_EQ("cxvalue", CO(absl::in_place, "cxvalue").value());
#endif
EXPECT_EQ("&", TypeQuals(lvalue.value()));
EXPECT_EQ("c&", TypeQuals(clvalue.value()));
EXPECT_EQ("c&", TypeQuals(lvalue_c.value()));
EXPECT_EQ("&&", TypeQuals(O(absl::in_place, "xvalue").value()));
#if !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG) && \
!defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG)
EXPECT_EQ("c&&", TypeQuals(CO(absl::in_place, "cxvalue").value()));
#endif
EXPECT_EQ("c&&", TypeQuals(OC(absl::in_place, "xvalue_c").value()));
// test on volatile type
using OV = absl::optional<volatile int>;
OV lvalue_v(absl::in_place, 42);
EXPECT_EQ(42, lvalue_v.value());
EXPECT_EQ(42, OV(42).value());
EXPECT_TRUE((std::is_same<volatile int&, decltype(lvalue_v.value())>::value));
EXPECT_TRUE((std::is_same<volatile int&&, decltype(OV(42).value())>::value));
// test exception throw on value()
absl::optional<int> empty;
#ifdef ABSL_HAVE_EXCEPTIONS
EXPECT_THROW(empty.value(), absl::bad_optional_access);
#else
EXPECT_DEATH(empty.value(), "Bad optional access");
#endif
// test constexpr value()
constexpr absl::optional<int> o1(1);
static_assert(1 == o1.value(), ""); // const &
#if !defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_MSVC_BUG) && \
!defined(ABSL_SKIP_OVERLOAD_TEST_DUE_TO_GCC_BUG)
using COI = const absl::optional<int>;
static_assert(2 == COI(2).value(), ""); // const &&
#endif
}

@Mizux Mizux changed the title types\optional_test.cc compilation issue with Visual Studio 2017 (VS v15.8) types\optional_test.cc compilation issue with Visual Studio 2017 (v15.8) Oct 19, 2018
@JonathanDCohen JonathanDCohen self-assigned this Nov 9, 2018
@JonathanDCohen
Copy link
Contributor

I'm currently working through all of our MSVC bugs. I'll add this to the list :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants