Skip to content

Incorrect detection of std::in_placeΒ #45

@Pesa

Description

@Pesa

optional.hpp seems to rely only on the C++ standard version in use to choose between the std::in_place facility from the standard library or its own implementation.

https://github.com/martinmoene/optional-lite/blob/86db12f3b6c2026ad83efd51c5ce3622bb06f1b8/include/nonstd/optional.hpp#L88-L99

However, simply compiling in C++17 mode doesn't guarantee that the standard library contains these facilities. For instance, this detection technique fails on Ubuntu 16.04 when compiling with clang-5.0 (and the default libstdc++):

$ clang++-5.0 -xc++ -std=c++17 -ferror-limit=5 -c -o /dev/null - <<< '#include "optional.hpp"'
In file included from <stdin>:1:
./optional.hpp:94:12: error: no member named 'in_place' in namespace 'std'
using std::in_place;
      ~~~~~^
./optional.hpp:95:12: error: no member named 'in_place_type' in namespace 'std'
using std::in_place_type;
      ~~~~~^
./optional.hpp:96:12: error: no member named 'in_place_index' in namespace 'std'
using std::in_place_index;
      ~~~~~^
./optional.hpp:97:12: error: no member named 'in_place_t' in namespace 'std'
using std::in_place_t;
      ~~~~~^
./optional.hpp:98:12: error: no member named 'in_place_type_t' in namespace 'std'
using std::in_place_type_t;
      ~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
6 errors generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions