2

Till now I've been using gcc for compiling my C++ code in Ubuntu 16.04 server edition. But since the latest features of C++17 (mainly concurrency and parallelism) are not convered by the latest gcc, while in clang many of them are, I've been starting to use clang. What surprised me is that for one of previously gcc-debugged C++ files, while compiling with gcc : gcc version 7.3.0 (Ubuntu 7.3.0-21ubuntu1~16.04) the execution goes fine, if compiling clang : clang version 6.0.0 (tags/RELEASE_600/final), the compilation says error: no member named 'make_optional' in namespace 'std' :

`marco@PC:~/marcoTensor$ g++ -std=c++17 bigMatricesDiv01.cpp
-obigMatricesDiv01
 marco@PC:~/marcoTensor$ ./bigMatricesDiv01
 Timer MTensor::Tensor2D A = randU2<double>(20,400,2.7,4.6) :  154 ms
 Timer MTensor::Tensor2D B = randN2<double>(20,400,3,2.6)  :111 ms
 Timer MTensor::Tensor2D ApB = A/B  :0 ms

  marco@PC:~/marcoTensor$ clang++ -std=c++17 -stdlib=libc++ -w -fcolor-
  diagnostics bigMatricesDiv01.cpp -obigMatricesDiv01 -lc++experimental
  In file included from bigMatricesDiv01.cpp:1:
  In file included from ./tensorTypes.h:1:
  In file included from ./MTensorUtils.h:1:
  In file included from ./MTensor.h:5:
  In file included from ./GeneralUtils.h:16:
  ./FunctionalApproach.h:953:27: error: no template named 'optional' in 
  namespace 'std'
  auto transform(const std::optional<T1>& opt, F f) -> 
  decltype(std::make_optional(f(opt.value()))){
                       ~~~~~^
./FunctionalApproach.h:953:68: error: no member named 'make_optional' in 
namespace 'std'
auto transform(const std::optional<T1>& opt, F f) ->   
decltype(std::make_optional(f(opt.value()))){
                                                          ~~~~~^
./FunctionalApproach.h:955:17: error: no member named 'make_optional' in  
namespace 'std'
return std::make_optional(f(opt.value()));
           ~~~~~^
3 errors generated.

` But: In FunctionalApproach.h:

#include <experimental/propagate_const>

#include <experimental/optional>

Any idea why clang says " no member named 'make_optional' in namespace 'std' "?

user2315094
  • 759
  • 3
  • 16
  • 29
  • Looks like it is defined in the namespace `std::experimental`: http://en.cppreference.com/w/cpp/experimental/optional/make_optional – clcto Jun 11 '18 at 16:53
  • @clcto when compiling with clang I use the flag -lc++experimental. Is it the right flag to tell the compiler that I'm using the std::experimental namespace? – user2315094 Jun 11 '18 at 17:02

1 Answers1

3

<experimental/optional> puts things in the std::experimental namespace. So that's where make_optional lives. The use of -lc++experimental does not mean that the contents of std::experimental are dumped into the std namespace.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982