Skip to content

Handle l-values and pointers in conditional operators #157108

@usx95

Description

@usx95
#include <string>

void foo(bool cond) {
    std::string* res;
    {
        std::string a = "a";
        std::string b = "b";
        res = cond ? &a : &b;
        res = &(cond ? a : b);
    }
    (void)*res;
}

void bar(bool cond) {
    std::string* res;
    {
        std::string a = "a";
        std::string b = "b";
        std::string* p = &a;
        std::string* q = &b;
        res = cond ? p : q;
    }
    (void)*res;
}

https://godbolt.org/z/rf6WKPG51

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions