Proposal: allow #elifdef and #elifndef

36 views
Skip to first unread message

Victor Vianna

unread,
Jan 5, 2026, 4:49:23 PM (6 days ago) Jan 5
to c...@chromium.org
Hi cxx,

The C++23 change to the styleguide just landed, but ~all features are in the "TBD" pool right now. I would like to move some of them to the "allowed" pool before announcing cpp23 availability to chromium-dev@ (otherwise the announcement is likely to just be ignored).

I propose to allow #elifdef and #elifndef (docs). An example usage can be seen here.

-- Victor

Joe Mason

unread,
Jan 5, 2026, 5:01:23 PM (6 days ago) Jan 5
to Victor Vianna, c...@chromium.org
SGTM!

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANFyMwxtVuv4jAFA7aYpc4XB8xsRDuEr3muE9pHk3Y8nHAxfcg%40mail.gmail.com.

David Benjamin

unread,
Jan 5, 2026, 5:06:15 PM (6 days ago) Jan 5
to Joe Mason, Victor Vianna, c...@chromium.org

Mark Mentovai

unread,
Jan 5, 2026, 5:50:41 PM (6 days ago) Jan 5
to David Benjamin, Joe Mason, Victor Vianna, cxx
I’m OK with this in general.

Be aware that we may have tools (PRESUBMITs, maybe?) with baked-in patterns to match preprocessor directives like these, and we should make sure that they handle the new tokens correctly before changing the rule.

Avi Drissman

unread,
Jan 6, 2026, 10:37:14 AM (5 days ago) Jan 6
to Mark Mentovai, David Benjamin, Joe Mason, Victor Vianna, cxx

Victor Vianna

unread,
Jan 6, 2026, 11:30:30 AM (5 days ago) Jan 6
to cxx, Avi Drissman, David Benjamin, Joe Mason, Victor Vianna, cxx, ma...@chromium.org
> Be aware that we may have tools (PRESUBMITs, maybe?) with baked-in patterns to match preprocessor directives like these, and we should make sure that they handle the new tokens correctly before changing the rule.

Good point. With this query, the closest I could find was this list, but it doesn't require updating because WebGL has its own set of preprocessor directives IIUC.
I also checked that `git cl format` works correctly with #elifdef, so I will go ahead and land crrev.com/c/7362614

Mark Mentovai

unread,
Jan 6, 2026, 12:07:44 PM (5 days ago) Jan 6
to Victor Vianna, cxx, Avi Drissman, David Benjamin, Joe Mason
Victor Vianna wrote:
> Be aware that we may have tools (PRESUBMITs, maybe?) with baked-in patterns to match preprocessor directives like these, and we should make sure that they handle the new tokens correctly before changing the rule.

Good point. With this query, the closest I could find was this list, but it doesn't require updating because WebGL has its own set of preprocessor directives IIUC.
I also checked that `git cl format` works correctly with #elifdef, so I will go ahead and land crrev.com/c/7362614

I was thinking about things like PRESUBMIT.py _CheckForInvalidIfDefinedMacrosInFile, which your query didn’t seem to turn up, because it didn’t mention elif in so many wordsbytes.

David Benjamin

unread,
Jan 6, 2026, 12:17:56 PM (5 days ago) Jan 6
to Mark Mentovai, Victor Vianna, cxx, Avi Drissman, Joe Mason
On Tue, Jan 6, 2026 at 12:07 PM Mark Mentovai <ma...@chromium.org> wrote:
Victor Vianna wrote:
> Be aware that we may have tools (PRESUBMITs, maybe?) with baked-in patterns to match preprocessor directives like these, and we should make sure that they handle the new tokens correctly before changing the rule.

Good point. With this query, the closest I could find was this list, but it doesn't require updating because WebGL has its own set of preprocessor directives IIUC.
I also checked that `git cl format` works correctly with #elifdef, so I will go ahead and land crrev.com/c/7362614

I was thinking about things like PRESUBMIT.py _CheckForInvalidIfDefinedMacrosInFile, which your query didn’t seem to turn up, because it didn’t mention elif in so many wordsbytes.

At a glance, that one might actually be fine with the .*, though adding a test is probably prudent. :-)

Victor Vianna

unread,
Jan 6, 2026, 12:45:21 PM (5 days ago) Jan 6
to cxx, David Benjamin, Victor Vianna, cxx, Avi Drissman, Joe Mason, ma...@chromium.org
> At a glance, that one might actually be fine with the .*, though adding a test is probably prudent. :-)

It is, adding the test in crrev.com/c/7390218
I replaced elif with ifdef in my original query and got this. PRESUBMIT.py _CheckForInvalidIfDefinedMacrosInFile was the only new case I found, so hopefully we're good now

Reply all
Reply to author
Forward
0 new messages