Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Closed

Description

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

Activity

  1. ghost added
    bug
    on Oct 14, 2023
  2. gregmarr commented on Dec 19, 2023

    @gregmarr
    Contributor

    Still, since this issue is not fixed, I would need to manually use an if statement and t.violation.

    Unless/until we have the ability to have an argument that is not evaluated, you could just protect the v.front() in the string as well.

    require(v.empty() || v.front() == 42, "`(!v.empty() ? v.front() : 0)$` is not 42.");.
    
  3. hsutter commented on Dec 20, 2023

    @hsutter
    Owner

    Fixed, thanks!

  4. added a commit that references this issue on Feb 1, 2024
    0827bab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions