r191274 - Handle standard libraries that miss out the space when defining the standard

Gao, Yunzhong yunzhong_gao at playstation.sony.com
Tue Sep 24 14:23:17 PDT 2013


Hi Richard,
I am seeing warnings like this:
  Lexer.cpp: In member function 'const char* clang::Lexer::LexUDSuffix(clang::Token&, const char*, bool)':
  Lexer.cpp:1662:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
I wonder if an explicit cast is needed?
- Gao.


> -----Original Message-----
> From: cfe-commits-bounces at cs.uiuc.edu [mailto:cfe-commits-
> bounces at cs.uiuc.edu] On Behalf Of Richard Smith
> Sent: Monday, September 23, 2013 9:06 PM
> To: cfe-commits at cs.uiuc.edu
> Subject: r191274 - Handle standard libraries that miss out the space when
> defining the standard
> 
> Author: rsmith
> Date: Mon Sep 23 23:06:10 2013
> New Revision: 191274
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=191274&view=rev
> Log:
> Handle standard libraries that miss out the space when defining the standard
> literal operators. Also, for now, allow the proposed C++1y "il", "i", and "if"
> suffixes too. (Will revert the latter if LWG decides not to go ahead with that
> change after all.)
> 
> Modified:
>     cfe/trunk/lib/Lex/Lexer.cpp
>     cfe/trunk/lib/Lex/LiteralSupport.cpp
>     cfe/trunk/test/SemaCXX/cxx1y-user-defined-literals.cpp
> 
> Modified: cfe/trunk/lib/Lex/Lexer.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Lex/Lexer.cpp?rev=191274&r1=191273&r2=191274&vie
> w=diff
> ==========================================================
> ====================
> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
> +++ cfe/trunk/lib/Lex/Lexer.cpp Mon Sep 23 23:06:10 2013
> @@ -29,6 +29,7 @@
>  #include "clang/Basic/SourceManager.h"
>  #include "clang/Lex/CodeCompletionHandler.h"
>  #include "clang/Lex/LexDiagnostic.h"
> +#include "clang/Lex/LiteralSupport.h"
>  #include "clang/Lex/Preprocessor.h"
>  #include "llvm/ADT/STLExtras.h"
>  #include "llvm/ADT/StringExtras.h"
> @@ -1638,12 +1639,33 @@ const char *Lexer::LexUDSuffix(Token &Re
>      bool IsUDSuffix = false;
>      if (C == '_')
>        IsUDSuffix = true;
> -    else if (IsStringLiteral && C == 's' && getLangOpts().CPlusPlus1y) {
> -      // In C++1y, "s" is a valid ud-suffix for a string literal.
> -      unsigned NextSize;
> -      if (!isIdentifierBody(getCharAndSizeNoWarn(CurPtr + Size, NextSize,
> -                                                 getLangOpts())))
> -        IsUDSuffix = true;
> +    else if (IsStringLiteral && getLangOpts().CPlusPlus1y) {
> +      // In C++1y, we need to look ahead a few characters to see if this is a
> +      // valid suffix for a string literal or a numeric literal (this could be
> +      // the 'operator""if' defining a numeric literal operator).
> +      const int MaxStandardSuffixLength = 3;
> +      char Buffer[MaxStandardSuffixLength] = { C };
> +      unsigned Consumed = Size;
> +      unsigned Chars = 1;
> +      while (true) {
> +        unsigned NextSize;
> +        char Next = getCharAndSizeNoWarn(CurPtr + Consumed, NextSize,
> +                                         getLangOpts());
> +        if (!isIdentifierBody(Next)) {
> +          // End of suffix. Check whether this is on the whitelist.
> +          IsUDSuffix = (Chars == 1 && Buffer[0] == 's') ||
> +                       NumericLiteralParser::isValidUDSuffix(
> +                           getLangOpts(), StringRef(Buffer, Chars));
> +          break;
> +        }
> +
> +        if (Chars == MaxStandardSuffixLength)
> +          // Too long: can't be a standard suffix.
> +          break;
> +
> +        Buffer[Chars++] = Next;
> +        Consumed += NextSize;
> +      }
>      }
> 
>      if (!IsUDSuffix) {
> 
> Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=191274&r1=191273&r2=19
> 1274&view=diff
> ==========================================================
> ====================
> --- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
> +++ cfe/trunk/lib/Lex/LiteralSupport.cpp Mon Sep 23 23:06:10 2013
> @@ -604,6 +604,9 @@ NumericLiteralParser::NumericLiteralPars
>            break;
>          }
>        }
> +      // "i", "if", and "il" are user-defined suffixes in C++1y.
> +      if (PP.getLangOpts().CPlusPlus1y && *s == 'i')
> +        break;
>        // fall through.
>      case 'j':
>      case 'J':
> @@ -665,9 +668,11 @@ bool NumericLiteralParser::isValidUDSuff
>      return false;
> 
>    // In C++1y, "s", "h", "min", "ms", "us", and "ns" are used in the library.
> +  // Per tweaked N3660, "il", "i", and "if" are also used in the library.
>    return llvm::StringSwitch<bool>(Suffix)
>        .Cases("h", "min", "s", true)
>        .Cases("ms", "us", "ns", true)
> +      .Cases("il", "i", "if", true)
>        .Default(false);
>  }
> 
> 
> Modified: cfe/trunk/test/SemaCXX/cxx1y-user-defined-literals.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-
> user-defined-literals.cpp?rev=191274&r1=191273&r2=191274&view=diff
> ==========================================================
> ====================
> --- cfe/trunk/test/SemaCXX/cxx1y-user-defined-literals.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx1y-user-defined-literals.cpp Mon Sep 23
> +++ 23:06:10 2013
> @@ -8,15 +8,23 @@ namespace std {
>    using size_t = decltype(sizeof(0));
> 
>    struct duration {};
> -  duration operator"" ns(unsigned long long);
> -  duration operator"" us(unsigned long long);
> -  duration operator"" ms(unsigned long long);
> -  duration operator"" s(unsigned long long);
> -  duration operator"" min(unsigned long long);
> -  duration operator"" h(unsigned long long);
> +  duration operator""ns(unsigned long long);  duration
> + operator""us(unsigned long long);  duration operator""ms(unsigned long
> + long);  duration operator""s(unsigned long long);  duration
> + operator""min(unsigned long long);  duration operator""h(unsigned long
> + long);
> 
>    struct string {};
> -  string operator"" s(const char*, size_t);
> +  string operator""s(const char*, size_t);
> +
> +  template<typename T> struct complex {};  complex<float>
> + operator""if(long double);  complex<float> operator""if(unsigned long
> + long);  complex<double> operator""i(long double);  complex<double>
> + operator""i(unsigned long long);  complex<long double>
> + operator""il(long double);  complex<long double> operator""il(unsigned
> + long long);
>  }
> 
>  #else
> @@ -29,4 +37,8 @@ char error = 'x's; // expected-error {{i  int _1z = 1z; //
> expected-error {{invalid suffix}}  int _1b = 1b; // expected-error {{invalid
> digit}}
> 
> +complex<float> cf1 = 1if, cf2 = 2.if, cf3 = 0x3if; complex<double> cd1
> += 1i, cd2 = 2.i, cd3 = 0b0110101i; complex<long double> cld1 = 1il,
> +cld2 = 2.il, cld3 = 0047il;
> +
>  #endif
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list