Skip to content

<string>: [regression] v17.10: string comparison yields erroneous results at compile time #5322

Description

@sdwe

Description

Comparison of std::string yields different results when performed at runtime vs. compile time:

The underlying compiler issue with respect to __builtin_memcmp() was reported in July 2024.
One commenter suggested reporting the problem here in the hope of generating the necessary attention.

Command-line test case

C:\Temp>type repro.cpp
#include <cassert>
#include <string>

int main()
{
    constexpr std::string a = "\x01";
    constexpr std::string b = "\xFF";
    
    auto r = (a < b);
    assert(r);

    constexpr auto c = (a < b);
    static_assert(c);
}

C:\Temp>cl /nologo /std:c++20 repro.cpp
repro.cpp
repro.cpp(13): error C2607: static assertion failed

Expected behavior

Compilation should succeed without error as it was the case until v17.9:

C:\Temp>cl /std:c++20 repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33523 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

repro.cpp
Microsoft (R) Incremental Linker Version 14.39.33523.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

STL version

Last working version:

Microsoft Visual Studio Professional 2022 (64-bit)
Version 17.9.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompilerCompiler work involvedfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions