Bug 83708 - Token-based policy broken by __VA_OPT__
Summary: Token-based policy broken by __VA_OPT__
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-06 01:24 UTC by Jun Woong
Modified: 2018-02-15 17:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jun Woong 2018-01-06 01:24:26 UTC
Use of __VA_OPT__ can break the token-based policy when those optional tokens do not come from arguments.

$ cat > foo.c
__VERSION__

#define foo(...) __VA_OPT__(foo)__VA_OPT__(bar)
foo(dummy)

$ gcc -E foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "foo.c"
"8.0.0 20180105 (experimental)"


foobar
Comment 1 Jason Merrill 2018-02-15 17:43:33 UTC
Author: jason
Date: Thu Feb 15 17:43:01 2018
New Revision: 257696

URL: https://gcc.gnu.org/viewcvs?rev=257696&root=gcc&view=rev
Log:
	PR preprocessor/83063 - __VA_OPT__ and ##

	PR preprocessor/83708
	* macro.c (vaopt_state): Reorder m_last_was_paste before m_state.
	(vaopt_state::vaopt_state): Adjust.
	(vaopt_state::update_flags): Add BEGIN and END.
	(vaopt_state::update): Return them.
	(copy_paste_flag): Factor out of replace_args.
	(last_token_is): New.
	(replace_args): Handle BEGIN and END.  Avoid padding there.
	(tokens_buff_last_token_ptr): Return NULL if no tokens.

Added:
    trunk/gcc/testsuite/c-c++-common/cpp/va-opt-2.c
    trunk/gcc/testsuite/c-c++-common/cpp/va-opt-3.c
Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/macro.c
Comment 2 Jason Merrill 2018-02-15 17:44:01 UTC
Fixed.