This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/52654] [C++11] Warn on overflow in user-defined literals


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52654

--- Comment #15 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> 2012-04-06 16:40:42 UTC ---
(In reply to comment #13)
> Created attachment 27105 [details]
> New patch incorporating recent suggestions.
> 
> Using warning_at, OPT_Woverflow, etc.
> Added a new enum for overflow type and used it everywhere.
> 

Well, sorry if I am nitpicking, but the code would be clearer if the enum was
declared in real.h, used by real_from_string and everywhere else, so one would
not need to do "overflow < 0" but "overflow == UNDERFLOW" or something similar
like "UNDERFLOWED". And OT_NONE is not very easy to understand, because I don't
know what OT is the build_ call, I would suggest "NO_OVERFLOW". Or perhaps:

real.h:
/* Enumerate the types of overflow that may occur.  */
enum overflow_type {
  overflow_underflowed = -1,
  overflow_none,
  overflow_overflowed
};

GCC source code is already hard enough to read. Every little thing helps.
But this is merely a suggestion. You should send your patch to gcc-patches and
wait and see what the maintainers say. I don't have the power to approve (or
reject) patches.

Also, I may be misunderstanding how the current code works and what you are
trying to achieve, but it is strange to me that you parse the number first as a
number and then, if it is indeed converted to a number warn. So why don't just
parse the number as a string, and if it is indeed converted to a number, then
convert the string to a number and warn? That is, in c-lex.c build the userdef
before any interpret_ is called, and store the raw string. Do not try to
interpret it. Then, in cp_parser_userdef_numeric_literal, when you know what
type you are expecting, you can call interpret_* and do all the magic to decide
whether this is actually a number or a string. It seems to me that this will 
do the work in one place, instead of moving stuff up and down the parser and
the lexer. Or maybe you already tried this and it didn't work for some reason?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]