Thanks to visit codestin.com
Credit goes to github.com

Skip to content

<xutility>: ranges::_Ssize_fn::operator() should have a noexcept-specifier #4107

@cpplearner

Description

@cpplearner

Describe the bug

ranges::ssize(a) is specified to be expression-equivalent to static_cast<D>(ranges::size(a)) (for some integer-like type D), which means applying noexcept to these two expressions should produce the same result. But due to a missing noexcept-specifier, noexcept(ranges::ssize(a)) is always false on MSVC, which is non-conforming.

This can be fixed by adding a conditional noexcept-specifier to ranges::_Ssize_fn::operator(). Since D is integer-like, the cast should never throw an exception, so the noexcept-specifier only needs to mention the ranges::size call.

I think this could be a "good first issue".

Command-line test case

D:\test>type test-ssize.cpp
#include <ranges>

int a[10];
static_assert(noexcept(std::ranges::ssize(a)));

D:\test>cl /Zs /std:c++20 test-ssize.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33030 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test-ssize.cpp
test-ssize.cpp(4): error C2607: static assertion failed

Expected behavior

no error

STL version

Microsoft Visual Studio Community 2022
Version 17.8.0 Preview 2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!good first issueGood for newcomersrangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions