microsoft / microsoft/STL

STL: Non-standard non-reserved identifiers available via standard headers

Open
#2,206 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
The C++ standard allows user-defined macros to have non-reserved names. However, MSVC STL introduces some non-standard non-reserved via standard headers, which makes user-defined macros with such names able to paralyze the MSVC STL implementation.

The list of names may be incomplete:

  • <exception> and <yvals_core.h>: stdext
  • <typeinfo> (ultimately, <vcruntime_typeinfo.h>): raw_name (#2195)

Maybe all of them should either be removed or have their names changed to reserved identifiers in vNext.

Command-line test case

C:\Temp>type repro.cpp
#define raw_name                      delete // <vcruntime_typeinfo.h>, via <typeinfo>

#define xtime_get                     delete // <xtimec.h>, via <chrono>, <xthreads.h>, <thread>, <mutex>, <condition_variable>
#define xtime                         delete // same as above
#define sec                           delete // same as above
#define nsec                          delete // same as above

#define stdext                        delete // <xhash>, <yvals_core.h>, via <iterator>

#define hash_compare                  delete // <xhash>, via <unordered_map>, <unordered_set>

#define checked_array_iterator        delete // <iterator>
#define unchecked_array_iterator      delete // <iterator>
#define make_checked_array_iterator   delete // <iterator>
#define make_unchecked_array_iterator delete // <iterator>

#define linear_congruential           delete // <random>
#define subtract_with_carry           delete // same as above
#define mersenne_twister              delete // same as above
#define discard_block                 delete // same as above
#define uniform_int                   delete // same as above
#define uniform_real                  delete // same as above

#include <typeinfo>
#include <chrono>
#include <unordered_map>
#include <random>
#include <iterator>

int main()
{
}

C:\Temp>cl /EHsc /W4 /WX /std:c++17 .\repro.cpp
用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30133 版
版权所有(C) Microsoft Corporation。保留所有权利。

repro.cpp
(omitted for short)
C1003: 错误计数超过 100;正在停止编译

Expected behavior
This program should compile.

STL version
Microsoft Visual Studio Community 2019
版本 16.11.2

Additional context
The MS CRT also provides some non-standard non-reserved names (e.g. fread_s). I don't know whether such issue has been reported or how to report it.

Fixed

  • #3594 removed xtime_get, xtime, sec, nsec.
  • #5763 removed TR1, including the tr1 namespace and the old <random> types linear_congruential, subtract_with_carry, mersenne_twister, discard_block, uniform_int, uniform_real.
  • #5764 removed hash_compare.
  • #5817 removed checked_array_iterator, unchecked_array_iterator, make_checked_array_iterator, make_unchecked_array_iterator.

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 by reproducing the command-line case in repro.cpp, then inspect the named headers: exception, yvals_core.h, typeinfo, vcruntime_typeinfo.h, and iterator. Verify that the remaining non-reserved names, especially stdext and raw_name, no longer prevent standard headers from compiling when user macros use them.

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.