https://bugs.kde.org/show_bug.cgi?id=415537

            Bug ID: 415537
           Summary: Syntax highlighter fails on C++17 if-statement with
                    initializer
           Product: kdevelop
           Version: 5.4.5
          Platform: Gentoo Packages
                OS: Linux
            Status: REPORTED
          Severity: minor
          Priority: NOR
         Component: Language Support: CPP (Clang-based)
          Assignee: kdevelop-bugs-n...@kde.org
          Reporter: k...@mattwhitlock.name
  Target Milestone: ---

SUMMARY

/* BEGIN example.cpp */

#include <mutex>
#include <optional>

std::mutex mutex;

extern std::optional<int> froop();
extern void frob(int val = 0);

void func1() {
        std::unique_lock lock { mutex, std::try_to_lock };  // OK
        // if-statement with expression condition
        if (lock) {  // OK
                frob();
                lock.unlock();  // OK
        }
}

void func2() {
        // if-statement with declaration condition
        if (std::unique_lock lock { mutex, std::try_to_lock }) {  // OK
                frob();
                lock.unlock();  // OK
        }
}

void func3() {
        // if-statement with initializer and expression condition
        if (std::unique_lock lock { mutex, std::try_to_lock };  // broken
            lock.owns_lock())  // broken
        {
                frob();
                lock.unlock();  // broken
        }
}

void func4() {
        // if-statement with initializer and declaration condition
        if (std::unique_lock lock { mutex };  // broken
            auto optval = froop())  // OK
        {
                frob(*optval);  // OK
                lock.unlock();  // broken
        }
}

/* END example.cpp */


OBSERVED RESULT

* If-statement initializers are not fully syntax highlighted. (Only
context-insensitive highlighting, such as Kate would do, is performed.)
* All variables declared via if-statement initializers are not highlighted at
subsequent uses, including within the condition expression of the if-statement.
* Note that code completion works as it should.


EXPECTED RESULT

* KDevelop's syntax highlighter should understand the C++17 if-statement with
initializer syntax.
* Local variables declared in if-statement initializers should be colored as
local variables, both when used in the succeeding if-statement conditions and
when used in the statement body/bodies.
* Note that local variables declared in if-statement initializers are in scope
throughout both the "true" body and the "false" (else) body (if there is one).
This is the same scoping rule as for if-statement declaration conditions.


SOFTWARE/OS VERSIONS

KDE Plasma Version: 5.17.4
KDE Frameworks Version: 5.65.0
Qt Version: 5.14.0

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to