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. c++11 error message when compiling c++14
Forum Updated to NodeBB v4.3 + New Features

c++11 error message when compiling c++14

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 939 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    I am using literals from c++14 in my code:

    // c++11
    constexpr long double operator"" _m(long double m){
        assert(m >= 0.0l && m < 10.0l); // c++14
        return m;
    }
    constexpr long double operator"" _s(long double s){
        return s;
    }
    
    
    // c++14
    constexpr long double operator""m(long double m){
        return m;
    }
    constexpr long double operator""s(long double s){
        return s;
    }
    

    I have changed my compiler setting in my pro file:

    CONFIG += c++14
    

    I get this error/warning:

    C:\Users\\Documents\programming\testing\test_rules\testrules.h:18: error: invalid suffix on literal; C++11 requires a space between literal and identifier
    

    Is there a way to suppress this error when compiling c++14?
    BTW, it still seems to compile correctly. It just throws an error.

    For reference.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, if your code isn't inside a standard library header you'll still need that _ prefix even for c++14, i.e. perhaps try:

      // c++14
      constexpr long double operator""_m(long double m){
          return m;
      }
      constexpr long double operator""_s(long double s){
          return s;
      }
      
      fcarneyF 1 Reply Last reply
      4
      • hskoglundH hskoglund

        Hi, if your code isn't inside a standard library header you'll still need that _ prefix even for c++14, i.e. perhaps try:

        // c++14
        constexpr long double operator""_m(long double m){
            return m;
        }
        constexpr long double operator""_s(long double s){
            return s;
        }
        
        fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        @hskoglund said in c++11 error message when compiling c++14:

        Hi, if your code isn't inside a standard library header you'll still need that _ prefix even for c++14

        Why would being in a standard library have any effect on using a literal as defined in c++14? The examples from CppCoreGuidelines show this exact example of using m and s. The point is to show intent through liberal use of literals. Where does it say you have to use underscores? I didnt see that in the other link I provided. Confused...

        Maybe I was not clear: The code compiles just fine and runs just fine. It is Qt Creator complaining when there is actually no compilation error.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          Crap, it does say this:

          may only appear as part of a standard library header
          

          That is strange. Thanks for the heads up.

          C++ is a perfectly valid school of magic.

          K 1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            Just as @hskoglund said all error messages go away if doing only this:

            constexpr long double operator""_m(long double m){
                assert(m >= 0.0l && m < 100.0l); // c++14
                return m;
            }
            constexpr long double operator""_s(long double s){
                return s;
            }
            

            Note no spaces between " and _. Darn reserved names and stuff!

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            0
            • fcarneyF fcarney

              Crap, it does say this:

              may only appear as part of a standard library header
              

              That is strange. Thanks for the heads up.

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @fcarney

              Are talking about the "code model" warnings/errors in qt creator?

              You can change it under "Tools"->"Options"->"{} C++"->"Code Model"
              Under "Diagnostic Configuration" you can choose another configuration or adjust the one used. The same syntax can be used as you would in suppressing warnings for compilation.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              3

              • Login

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