[Bug preprocessor/89665] inconsistent macro expansion

2019-03-11 Thread gciofono at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89665

--- Comment #2 from Giacinto Cifelli  ---
It mentions the following:
"A parameter in the replacement list, unless preceded by a # or ##
preprocessing token or followed by a ## preprocessing token (see below), is
replaced by the corresponding argument after all macros contained therein have
been expanded."
(in a 2005 free draft on internet from WG14, but I have hopes that the official
ISO document hasn't changed this)

So, this is not really helpful. It can lead to the current lazy expansion or to
the expansion of each argument each time it is used, or possibly to the
pre-expansion of the list of parameters. All options are possible.

[Bug preprocessor/89665] New: inconsistent macro expansion

2019-03-11 Thread gciofono at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89665

Bug ID: 89665
   Summary: inconsistent macro expansion
   Product: gcc
   Version: 7.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: preprocessor
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gciofono at gmail dot com
  Target Milestone: ---

Created attachment 45941
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45941=edit
hellomacro.c shows the inconsistent macro expansion of gcc.

The preprocessing of the macros follows a lazy-expansion algorithm that is not
entirely satisfying, nor exactly matching the description of the gcc guide,
paragraph 3.10.6 Argument Prescan.

I find that an argument should be expanded each time it is used, or
(suboptimal) each time it is declared, but the gcc preprocessor does none.

My full gcc version with Ubuntu 18.04 is:
   gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0


please compile with (includes only stdio.h but it is unavoidable to see the
output):
   gcc -v -save-temps -o hm hellomacro.c

the commented result of execution is:

$ ./hm
0-1-2-3-4<< 5 times expansion of __COUNTER__, as expected
x<< INCONSISTENCY: no expansion to __COUNTER__, because not used
direcly
5-5-5-5-5<< inconsistency: 1 expansion of counter. 5 times would have been
better
x<< inconsistency: 1 expansion of counter, because of it indirect
use, but finally discarded like two lines above
7-7-7-7-7<< output of the current counter (6 is skipped).