LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 35381 - C++17 if-with-initializer doesn't compile with empty init-statement
Summary: C++17 if-with-initializer doesn't compile with empty init-statement
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++17 (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-22 02:57 PST by Timur Doumler
Modified: 2018-04-13 14:25 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s): r327782


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timur Doumler 2017-11-22 02:57:08 PST
Overview:
An if-with-initializer with an empty init-statement followed by a semicolon is valid in C++17, but rejected by clang (trunk).

Steps to reproduce:
Compile this code:

int main()
{
   if (; true);
}

Actual Results:
The following errors are shown:

3 : <source>:3:6: error: expected expression
        if (; true);
            ^
3 : <source>:3:12: error: extraneous ')' before ';'
        if (; true);
                  ^

Expected results:
The code should compile.

Additional information:
According to the C++17 grammar, the init-statement in an if-with-initializer is allowed to be an empty expression followed by a semicolon.

GCC 7.2 and MSVC 19 2017 both accept this code.
Comment 1 Nicolas Lesser 2018-04-13 14:25:23 PDT
This was fixed some time ago, thanks! :)