Bug 257696 - C++ preprocessor parser chokes on hex numbers in parentheses
Summary: C++ preprocessor parser chokes on hex numbers in parentheses
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Unclassified
Component: Language Support: CPP (old) (show other bugs)
Version: git master
Platform: Unlisted Binaries Linux
: VHI major (vote)
Target Milestone: 4.2.0
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-23 13:48 UTC by Alexander
Modified: 2013-03-31 00:55 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2010-11-23 13:48:44 UTC
Version:           SVN (using KDE 4.5.3) 
OS:                Linux

I'm using KDevelop & friends master from git (2010-11-23).

Consider the following code sample (__GNUC__ is just a random macro):

#if (__GNUC__ >= 0x800)
#endif 

The first line is error-highlighted as:
Expected ")", found x.

The same happens with:
#if __GNUC__ >= (0x800)
#endif 

However, no error occurs with:
#if __GNUC__ >= 0x800
#endif 

Thanks

Reproducible: Always




openSUSE 11.3 x86_64 with KDE 4.5.3 from OBS.
Comment 1 Milian Wolff 2011-01-03 13:08:50 UTC
if possible this should be fixed for 4.2.0
Comment 2 David Nolden 2011-01-13 01:04:26 UTC
commit 23c67db831373ecbed403eb885e47c61bf83a533
branch master
Author: David nolden <david.nolden.kde@art-master.de>
Date:   Wed Jan 12 21:27:34 2011 +0100

    Properly skip hexadecimal numbers in pp_skip_number. The problem is that everything starting at the "x" is pre-tokenized into one IndexedString by tokenizeFromByteArray, so we have to handle the case that the input is not a single character.
    BUG: 257696

diff --git a/languages/cpp/parser/rpp/pp-scanner.cpp b/languages/cpp/parser/rpp/pp-scanner.cpp
index 84eb40e..e7d2576 100644
--- a/languages/cpp/parser/rpp/pp-scanner.cpp
+++ b/languages/cpp/parser/rpp/pp-scanner.cpp
@@ -171,7 +171,7 @@ uint pp_skip_identifier::operator()(Stream& input)
 void pp_skip_number::operator()(Stream& input, Stream& output)
 {
   while (!input.atEnd()) {
-    if (!isLetterOrNumber(input.current()) && input != '_')
+    if (isCharacter(input.current()) && !isLetterOrNumber(input.current()) && input != '_')
         return;
 
     output << input;
diff --git a/languages/cpp/parser/tests/test_parser.cpp b/languages/cpp/parser/tests/test_parser.cpp
index b4dddc2..2e683e4 100644
--- a/languages/cpp/parser/tests/test_parser.cpp
+++ b/languages/cpp/parser/tests/test_parser.cpp
@@ -449,6 +449,7 @@ private slots:
     QCOMPARE(preprocess("#if ~1\n#define NUMBER 10\n#else\n#define NUMBER 20\n#endif\nNUMBER").trimmed(), QString("10"));
     QCOMPARE(preprocess("#define MACRO(a, b) ab\nMACRO\n(aa, bb)").trimmed(), QString("ab"));
     QCOMPARE(preprocess("#define MACRO(a, b) ab\nMACRO(aa,\n bb)").trimmed(), QString("ab"));
+    QCOMPARE(preprocess("#if 0x1\n #define NUMBER 10\n#else\n#define NUMBER 20\n#endif\nNUMBER\n").trimmed(), QString("10"));
   }
 
   void testPreprocessorStringify() {
Comment 3 David Nolden 2011-01-13 21:55:16 UTC
commit a46663a1f93c6ecfbc228d69797ea25db361c6ac
branch 4.2
Author: David nolden <david.nolden.kde@art-master.de>
Date:   Wed Jan 12 21:27:34 2011 +0100

    backport from master: Properly skip hexadecimal numbers in pp_skip_number. The problem is that everything starting at the "x" is pre-tokenized into one IndexedString by tokenizeFromByteArray, so we have to handle the case that the input is not a single character.
    CCBUG: 257696

diff --git a/languages/cpp/parser/rpp/pp-scanner.cpp b/languages/cpp/parser/rpp/pp-scanner.cpp
index 84eb40e..e7d2576 100644
--- a/languages/cpp/parser/rpp/pp-scanner.cpp
+++ b/languages/cpp/parser/rpp/pp-scanner.cpp
@@ -171,7 +171,7 @@ uint pp_skip_identifier::operator()(Stream& input)
 void pp_skip_number::operator()(Stream& input, Stream& output)
 {
   while (!input.atEnd()) {
-    if (!isLetterOrNumber(input.current()) && input != '_')
+    if (isCharacter(input.current()) && !isLetterOrNumber(input.current()) && input != '_')
         return;
 
     output << input;
diff --git a/languages/cpp/parser/tests/test_parser.cpp b/languages/cpp/parser/tests/test_parser.cpp
index b4dddc2..2e683e4 100644
--- a/languages/cpp/parser/tests/test_parser.cpp
+++ b/languages/cpp/parser/tests/test_parser.cpp
@@ -449,6 +449,7 @@ private slots:
     QCOMPARE(preprocess("#if ~1\n#define NUMBER 10\n#else\n#define NUMBER 20\n#endif\nNUMBER").trimmed(), QString("10"));
     QCOMPARE(preprocess("#define MACRO(a, b) ab\nMACRO\n(aa, bb)").trimmed(), QString("ab"));
     QCOMPARE(preprocess("#define MACRO(a, b) ab\nMACRO(aa,\n bb)").trimmed(), QString("ab"));
+    QCOMPARE(preprocess("#if 0x1\n #define NUMBER 10\n#else\n#define NUMBER 20\n#endif\nNUMBER\n").trimmed(), QString("10"));
   }
 
   void testPreprocessorStringify() {
Comment 4 Aleix Pol 2013-03-31 00:55:11 UTC
Moving all the bugs from the CPP Parser. It was not well defined the difference between it and C++ Language Support and people kept reporting in both places indistinctively