Skip to content

[BUG] Generalize _string-literal_ of contract like C++26's static_assert #751

Closed
@JohelEGP

Description

@JohelEGP

Title: Generalize string-literal of contract like C++26's static_assert.

Description:

Custom text output after a contract failure isn't part of the Contracts' MVP.
If Cpp2's contracts feature is going to have this anyways,
we could craft better diagnostics messages
if its second argument behaved like that of static_assert in C++26.

Minimal reproducer (https://cpp2.godbolt.org/z/GYqdx3WTE):

// After P2361R6 and P2741R3:
static_assert(std::is_same_v<int, decltype(0)>, std::string("0") + " was not `int`.");
main: () = {
  [[assert: std::is_same_v<int, decltype(0)>, std::string("0") + " was not `int`."]]
}
Commands:
cppfront main.cpp2
clang++18 -std=c++26 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: Program returned: 0.

Actual result and error: main.cpp2(4,47): error: expected contract message string (at 'std').

See also:

1697303665
1697303677
1697303684

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions