Skip to content

[clang-tidy] "readability-container-data-pointer" - should not warn in non-const pointers usage before C++17 #147924

Open
@denzor200

Description

@denzor200

Assume for this example:

std::string a = "test", b = "eest";
std::memcpy(&a[0], &b[0], a.size());

The check will produce wrong code for C++11 and C++14, but correct for C++17 and newer:

std::string a = "test", b = "eest";
std::memcpy(a.data(), b.data(), a.size());  // error: cannot initialize a parameter of type 'void *' with an rvalue of type 'const char *' 

I expect this check to remain for C++17 as it is, but for older will produce this code:

std::string a = "test", b = "eest";
std::memcpy(&a[0], b.data(), a.size());

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions