[PATCH] Consider unsigned long for non-u/U decimal literals (C90/C++03)

Richard Smith richard at metafoo.co.uk
Thu May 28 16:23:18 PDT 2015


Sorry for the delay.

Can you combine the test files together into a single file with more `RUN:` lines (perhaps with `-D`s for the things that change between the old and new modes, and `-x` to specify C versus C++ input)? Note that `expected-*` comments within #if'd out regions are ignored. That'll make it much more obvious what you're changing and what is expected to change between modes. (There are also some costs associated with the number of separate test files that can be reduced by doing this.)


================
Comment at: include/clang/Basic/DiagnosticCommonKinds.td:119
@@ +118,3 @@
+  InGroup<ImplicitlyUnsignedLiteral>;
+def warn_old_implicitly_unsigned_long : Warning<
+  "integer literal is of type unsigned long only when %select{C99|C++11}0 "
----------------
In C++98, this should probably be an `ExtWarn` rather than a `Warning`, because this case has undefined behavior. Splitting this into two warnings would also allow you to put the warning into `-Wc99-compat` or `-Wc++11-compat` as appropriate, and to indicate that the C++98 case has undefined behavior.

================
Comment at: include/clang/Basic/DiagnosticCommonKinds.td:120-121
@@ +119,4 @@
+def warn_old_implicitly_unsigned_long : Warning<
+  "integer literal is of type unsigned long only when %select{C99|C++11}0 "
+  "or higher is not enabled">,
+  InGroup<ImplicitlyUnsignedLiteral>;
----------------
It would be clearer and more useful to phrase this as:

  "integer literal is too large to be represented in type 'long', interpreting as 'unsigned long'; this literal will have type '%select{long long|unsigned long long}0' in C99 onwards"

(with s/C99/C++11/ for the C++98 warning.)

You can easily compute the signedness of the `long long` in SemaExpr by checking if `LongLongSize > LongSize`.

http://reviews.llvm.org/D9794

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list