[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevelop/4.6] projectmanagers/cmake/parser: Fix cmake manager to not rely on undefined evaluation o
From:       Milian Wolff <mail () milianw ! de>
Date:       2013-11-16 14:12:03
Message-ID: E1VhgbT-0002hM-Fh () scm ! kde ! org
[Download RAW message or body]

Git commit e7adea3ef86f743707cfc0b0565d657dac7158ad by Milian Wolff.
Committed on 16/11/2013 at 14:09.
Pushed by mwolff into branch '4.6'.

Fix cmake manager to not rely on undefined evaluation order.

Compiling with clang showed tons of test failures. The issue was
basically due to something like:

QStack<int> s;
foo(s.pop(), s.count());

The code relied on a right-to-left evaluation, but this is undefined
behavior and clang is perfectly fine with breaking this. Note that
commas are not synchronization points. To fix this, one has
to rewrite the above as

QStack<int> s;
int val = s.pop();
foo(val, s.count() + 1);

M  +6    -2    projectmanagers/cmake/parser/cmakeprojectvisitor.cpp

http://commits.kde.org/kdevelop/e7adea3ef86f743707cfc0b0565d657dac7158ad

diff --git a/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp \
b/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp index ba65509..5defb03 100644
--- a/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp
+++ b/projectmanagers/cmake/parser/cmakeprojectvisitor.cpp
@@ -112,8 +112,12 @@ QList< CMakeProjectVisitor::IntPair > \
CMakeProjectVisitor::parseArgument(const Q  gotDollar=false;
                 break;
             case '}':
-                if(!opened.isEmpty())
-                    pos.append(IntPair(opened.pop(), i, opened.count()));
+                if(!opened.isEmpty()) {
+                    // note: don't merge this into the function call below,
+                    // the evaluation order is undefined then!
+                    int start = opened.pop();
+                    pos.append(IntPair(start, i, opened.count() + 1));
+                }
                 break;
         }
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic