Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Specifying C++17 stops C++14 features
Forum Updated to NodeBB v4.3 + New Features

Specifying C++17 stops C++14 features

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m3g1dd
    wrote on last edited by m3g1dd
    #1

    Environment

    Qt 5.11.3
    macOS 10.13.6 High Sierra
    Xcode version 9.4.1

    Clang++ is:

    $ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -v
    Apple LLVM version 9.1.0 (clang-902.0.39.2)
    

    Code

    C++ code is:

    template<class T, class O = T>
    using IteratorOnly = std::enable_if_t<
        !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
    >;
    

    C++14 added type trait *_t versions and C++17 added *_v versions. So, compiling the code with C++17 is expected to work.

    Observation

    Putting CONFIG += c++14 inside QMake project file, throws one error:

    error: no template named 'is_same_v' in namespace 'std'; did you mean 'is_same'?

    Putting CONFIG += c++17 inside QMake project file, throws two errors:

    error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?

    error: no template named 'is_same_v' in namespace 'std'; did you mean 'is_same'?

    Problem

    I cannot figure out the observation cause. Is it due to a bad installation of the standard library/compiler? Any other possibility?

    Note

    I'm able to run the same code on these without any problem:

    • Windows 10, Qt 5.12.9, MS Visual Studio 2017
    • Linux openSUSE Leap 15.1, Qt 5.12.7, GCC 7.5.0
    1 Reply Last reply
    0
    • M Offline
      M Offline
      m3g1dd
      wrote on last edited by
      #7

      Finally, I used C++14 on QMake project file:

      CONFIG += c++14
      QMAKE_CXXFLAGS += -std=c++14
      

      Then this error is received:

      error: no template named 'is_same_v' in namespace 'std'; did you mean 'is_same'?

      I bypass the error by this:

      #ifdef __APPLE__
      
      // On our current macOS build environment:
      // Qt 5.11.3
      // macOS 10.13.6 High Sierra
      // Xcode version 9.4.1
      //
      // C++14 works for 'std::enable_if_t' but not `std::is_same_v`
      // C++17 works for none of them!
      //
      // A workarond is to self-define `is_same_v` according to this:
      // https://en.cppreference.com/w/cpp/types/is_same
      
      template< class T, class U >
      inline constexpr bool is_same_v = std::is_same<T, U>::value;
      
      template<class T, class O = T>
      using IteratorOnly = std::enable_if_t<
          !is_same_v<typename std::iterator_traits<T>::value_type, void>, O
      >;
      
      #else // __APPLE__
      
      template<class T, class O = T>
      using IteratorOnly = std::enable_if_t<
          !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
      >;
      
      #endif // __APPLE__
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        m3g1dd
        wrote on last edited by
        #2

        Another observation

        CONFIG += c++14 inside QMake project file, invokes clang++ with std=gnu++1y flag:

        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++1y  -arch x86_64 -isysroot ...
        

        CONFIG += c++17 inside QMake project file, invokes clang++ with std=gnu++11 flag:

        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11  -arch x86_64 -isysroot ...  
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          m3g1dd
          wrote on last edited by m3g1dd
          #3

          Yet another observation

          Putting QMAKE_CXXFLAGS += -std=c++14 inside QMake project file, passes both -std=c++14 and -std=gnu++11 to clang++:

          /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -std=c++14 -g -std=gnu++11  -arch x86_64 -isysroot ...
          

          Putting QMAKE_CXXFLAGS += -std=c++17 inside QMake project file, passes both -std=c++17 and -std=gnu++11 flags to clang++:

          /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -std=c++17 -g -std=gnu++11  -arch x86_64 -isysroot ...
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Upgrade your Qt version to a version which adds the proper flags or add them correctly by your own. 5.11 is too old to support the correct -std=c++17 flag.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            M 1 Reply Last reply
            2
            • Christian EhrlicherC Christian Ehrlicher

              Upgrade your Qt version to a version which adds the proper flags or add them correctly by your own. 5.11 is too old to support the correct -std=c++17 flag.

              M Offline
              M Offline
              m3g1dd
              wrote on last edited by
              #5

              @Christian-Ehrlicher Is there any reference on how to add my own proper flags to Qt 5.11? I have never done it before, thanks!

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Maybe in the qmake documentation. I don't use qmake since ages so I can't really help here.
                Maybe you can remove flags with QMAKE_CXXFLAGS -= -std=c++11 ?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  m3g1dd
                  wrote on last edited by
                  #7

                  Finally, I used C++14 on QMake project file:

                  CONFIG += c++14
                  QMAKE_CXXFLAGS += -std=c++14
                  

                  Then this error is received:

                  error: no template named 'is_same_v' in namespace 'std'; did you mean 'is_same'?

                  I bypass the error by this:

                  #ifdef __APPLE__
                  
                  // On our current macOS build environment:
                  // Qt 5.11.3
                  // macOS 10.13.6 High Sierra
                  // Xcode version 9.4.1
                  //
                  // C++14 works for 'std::enable_if_t' but not `std::is_same_v`
                  // C++17 works for none of them!
                  //
                  // A workarond is to self-define `is_same_v` according to this:
                  // https://en.cppreference.com/w/cpp/types/is_same
                  
                  template< class T, class U >
                  inline constexpr bool is_same_v = std::is_same<T, U>::value;
                  
                  template<class T, class O = T>
                  using IteratorOnly = std::enable_if_t<
                      !is_same_v<typename std::iterator_traits<T>::value_type, void>, O
                  >;
                  
                  #else // __APPLE__
                  
                  template<class T, class O = T>
                  using IteratorOnly = std::enable_if_t<
                      !std::is_same_v<typename std::iterator_traits<T>::value_type, void>, O
                  >;
                  
                  #endif // __APPLE__
                  
                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved