microsoft / microsoft/STL

`<cassert>`: assert's `_wassert` is shadowable

Open
#5,408 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

UCRT
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug

Was checking out cppreference and saw it describing non-compliance in the msvc implementation of assert due to _wassert not taking __func__ and I realised that _wassert is not a reserved identifier and thus can be shadowed

I don't know if this is the job of this repo? I couldn't find the assert macro with a cursory overview, and have previously flagged this issue via the microsoft developer community: https://developercommunity.microsoft.com/t/assert:-_wassert-can-be-shadowed/10741373 (where I was originally told it wasn't an issue but oh well)

Thought I would also flag it here just in case that was the more correct place. Even if its not at least there will be a closed issue to refer to.

Command-line test case

https://godbolt.org/z/j9hWKaa7E

#include <cassert>
#include <iostream>

int main() {
    constexpr auto _wassert = [](const auto&...){};

    assert(1 + 1 != 2);
    std::cout << "Uh oh";
}

is able to reach the print due to the _wassert hyjacking the reporting

Expected behavior

I would expect that it doesn't do this since its technically non-compliant.
Im not sure about abi, but I would have thought it fairly trivial to make a __wassert function which just forwards it arguments to _wassert

The example provided is more just my fun example of what this can do in the worst case, I think it more likely that this is an issue when porting code between compilers, either causing a compile error or unexpected behaviour

If someone really wanted to abuse this it being a reserved identifier or not wouldn't stop them though

STL version

Every stl version ever? (or none if its not actually the STL's job)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the assert implementation and reproduce the reported behavior using the linked Godbolt command-line test case. Determine whether the implementation owns this behavior and whether changing the internal _wassert entry point affects ABI; done means the reporting path cannot be shadowed through this non-reserved identifier while preserving expected assert behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.