Compile error when using a member of a user-defined literal

后端 未结 1 732
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 01:25

When compiling this code (without any header)

template 
struct Temperature {
    T temp;

    explicit Temperature(T t)
        : temp(t)
          


        
相关标签:
1条回答
  • 2020-12-07 01:46

    Preprocessing numbers are odd beasts, specified mostly to make the preprocessor easier to write.

    pp-number:
        digit
        . digit
        pp-number digit
        pp-number identifier-nondigit
        pp-number ' digit
        pp-number ' nondigit
        pp-number e sign
        pp-number E sign
        pp-number p sign
        pp-number P sign
        pp-number .
    

    12 is a valid pp-number token, so is 0xe+foo (see the example in [lex.pptoken]/4), and so is .12.CA'TS_RULE..56.me+owp-urr. If the latter two make it past translation phase 6, then the program is ill-formed because it cannot be converted to a valid token in phase 7. Until then, however, it is valid, so maximal munch says we parse 0xe+foo or 100.0_f.temp as a single preprocessing token.

    0 讨论(0)
提交回复
热议问题