This is an archive of the discontinued LLVM Phabricator instance.

Enable the support for digit separators in C mode in Clang (to be compatible with MSVC)
Needs ReviewPublic

Authored by Manna on Jun 20 2018, 10:32 AM.

Details

Summary

This patch enables the support for digit separators in C mode in Clang. The digit separators are not supported in C mode but are supported in C++ mode in Clang.

Digit Separators are supported in both C and C++ modes in MS VC/C++ and Intel C/C++ compiler.

To be compatible with MSVC, I have enabled the support for digit separators in C mode in clang.

Diff Detail

Event Timeline

Manna created this revision.Jun 20 2018, 10:32 AM
rnk added inline comments.Jun 20 2018, 1:41 PM
lib/Lex/Lexer.cpp
1765

This is a conforming extension, so please check MicrosoftExt instead of MSVCCompat.

Manna updated this revision to Diff 152166.Jun 20 2018, 2:17 PM

Thanks for looking into the patch. I have made changes to check MicrosoftExt instead of MSVCCompat.

Manna marked an inline comment as done.Jun 20 2018, 2:19 PM
Manna added inline comments.
lib/Lex/Lexer.cpp
1765

checked MicrosoftExt instead of MSVCCompat

rnk added inline comments.Jun 20 2018, 3:26 PM
test/SemaCXX/digit_separators.c
2

You should explicitly pass -std=c++11 here and -fms-extensions, otherwise the test will fail now.

It's actually not (quite) a conforming extension: http://eel.is/c++draft/diff.cpp11.lex#1

Another example:

#define X(a)
X(1'a"b')

This is valid without the extension (you get a 1 token followed by a 'a"b' token) but undefined behavior with this extension due to an unmatched ".

But it's fairly close to being a conforming extension. I'm not sure how pedantic we want to be about this.

lib/Lex/Lexer.cpp
1765

Please remove the redundant parentheses.

Manna updated this revision to Diff 153795.Jul 2 2018, 2:17 PM
Manna marked an inline comment as done.

Thanks for the feedback. The patch is updated based on it.

Manna marked an inline comment as done.Jul 2 2018, 2:18 PM
Manna added inline comments.
test/SemaCXX/digit_separators.c
2

This test case is a ‘.c’ file, so it is compiling as a C program.

"-std=c++11" can't be explicitly passed here.
The test fails with this option "-std=c++11" and generates error:
invalid argument '-std=c++11' not allowed with 'C'.

The test passes without this option: "-std=c++11".