TartanLlama / optional

C++11/14/17 std::optional with functional-style extensions and reference support
https://tl.tartanllama.xyz
Creative Commons Zero v1.0 Universal
832 stars 64 forks source link

CTAD on MSVC fails #29

Open EmilyMansfield opened 5 years ago

EmilyMansfield commented 5 years ago

Hi, first of all thanks for this library!

On MSVC 19.21 with C++17, CTAD fails with tl::optional whereas it works with std::optional:

tl::optional o = 3; // Cannot deduce T
std::optional o = 3; // Deduces T to be int

I think this is just a case of missing std::optional's deduction guide, since adding that in fixes it, but strangely Clang and GCC don't seem to need the guide and deduce T to be int anyway. I don't know enough about CTAD to know exactly what's going on here, so sorry if this isn't actually a bug in tl::optional and is instead a compiler bug.

TartanLlama commented 5 years ago

Thanks for the report! Ah, it's because MSVC doesn't set __cplusplus properly unless you pass /Zc:__cplusplus, and the deduction guide is behind an ifdef. Will see if there's a more foolproof way of detecting C++17 mode for MSVC without that switch.

EmilyMansfield commented 5 years ago

Ah gotcha, that's good to know in general! I'll set that switch for now, thanks :+1: