Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<new>: Standard Library Header Units 'error C4430: missing type specifier' with /translateInclude #1706

Closed
StephanTLavavej opened this issue Mar 2, 2021 · 4 comments
Labels
bug Something isn't working compiler Compiler work involved external This issue is unrelated to the STL

Comments

@StephanTLavavej
Copy link
Member

Reported by @olgaark. Related to #1694.

C:\Temp\REPRO>set X_INC=D:\GitHub\STL\out\build\x86\out\inc

C:\Temp\REPRO>set X_COMMON_OPTIONS=/EHsc /nologo /W4 /MDd /Od /std:c++latest /permissive- /Zc:inline /Zc:preprocessor /c

C:\Temp\REPRO>cl %X_COMMON_OPTIONS% /ifcOutput use_ansi.h.ifc /sourceDependencies use_ansi.h.ifc.d.json /exportHeader /translateInclude /TP "%X_INC%\use_ansi.h"
use_ansi.h

C:\Temp\REPRO>cl %X_COMMON_OPTIONS% /headerUnit "%X_INC%\use_ansi.h=use_ansi.h.ifc" /ifcOutput yvals.h.ifc /sourceDependencies yvals.h.ifc.d.json /exportHeader /translateInclude /TP "%X_INC%\yvals.h"
yvals.h

C:\Temp\REPRO>cl %X_COMMON_OPTIONS% /headerUnit "%X_INC%\use_ansi.h=use_ansi.h.ifc" /headerUnit "%X_INC%\yvals.h=yvals.h.ifc" /ifcOutput exception.ifc /sourceDependencies exception.ifc.d.json /exportHeader /translateInclude /TP "%X_INC%\exception"
exception

C:\Temp\REPRO>cl %X_COMMON_OPTIONS% /headerUnit "%X_INC%\use_ansi.h=use_ansi.h.ifc" /headerUnit "%X_INC%\yvals.h=yvals.h.ifc" /headerUnit "%X_INC%\exception=exception.ifc" /ifcOutput new.ifc /sourceDependencies new.ifc.d.json /exportHeader /translateInclude /TP "%X_INC%\new"
new
D:\GitHub\STL\out\build\x86\out\inc\new(55): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
D:\GitHub\STL\out\build\x86\out\inc\new(55): error C2146: syntax error: missing ';' before identifier 'new_handler'
D:\GitHub\STL\out\build\x86\out\inc\new(56): error C2061: syntax error: identifier 'new_handler'

STL/stl/inc/new

Lines 49 to 55 in 30ac440

#if !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS)
// handler for operator new failures
using new_handler = void(__CLRCALL_PURE_OR_CDECL*)();
#endif // !defined(_INC_NEW) || !defined(_MSC_EXTENSIONS)
// FUNCTION AND OBJECT DECLARATIONS
_CRTIMP2 new_handler __cdecl set_new_handler(_In_opt_ new_handler) noexcept;

Preprocessing <new> classically with cl %X_COMMON_OPTIONS% /P /TP "%X_INC%\new" shows that this code should expand to:

using new_handler = void(__cdecl *)();
#line 53 "D:\\GitHub\\STL\\out\\build\\x86\\out\\inc\\new"


 new_handler __cdecl set_new_handler( new_handler) noexcept;

I'm not sure what's happening with /translateInclude. (If I attempt to add /P to the /translateInclude command line, I get an ICE where <new> tries to include <exception>.)

@StephanTLavavej StephanTLavavej added bug Something isn't working compiler Compiler work involved labels Mar 2, 2021
@StephanTLavavej
Copy link
Member Author

The problem appears to be with _CRTIMP2 - if I edit <new> to remove that, the error goes away.

This is defined by <crtdefs.h> as:

#ifndef _CRTIMP2
    #if defined CRTDLL2 && defined _CRTBLD
        #define _CRTIMP2 __declspec(dllexport)
    #else
        #define _CRTIMP2
    #endif
#endif

(that is, it's defined to nothing for ordinary users; it's __declspec(dllexport) when building the STL's DLL)

and it's included via the chain <new> includes <exception> includes <yvals.h> includes <crtdefs.h>:

#include <exception>

#include <yvals.h>

#include <crtdefs.h>

I'm guessing this is a compiler bug related to headers defining macros that expand to nothing.

@cpplearner
Copy link
Contributor

cpplearner commented Mar 2, 2021

It seems that a header unit does not "export" macros that were imported from another header unit.

D:\test>type a.h
#define FOO extern

D:\test>type b.h
#include "a.h"

D:\test>type c.h
#include "b.h"

FOO int x;

D:\test>set OPTIONS=/EHsc /nologo /std:c++latest /c /exportHeader /translateInclude

D:\test>cl %OPTIONS% /ifcOutput a.h.ifc a.h
a.h

D:\test>cl %OPTIONS% /ifcOutput b.h.ifc /headerUnit a.h=a.h.ifc b.h
b.h

D:\test>cl %OPTIONS% /headerUnit a.h=a.h.ifc /headerUnit b.h=b.h.ifc c.h
c.h
D:/test/c.h(3): error C2144: syntax error: 'int' should be preceded by ';'
D:/test/c.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

[cpp.import]/5 is a bit hard to interpret, but I believe that such macros should be exported.

@StephanTLavavej
Copy link
Member Author

Confirmed, this is a compiler bug. Thanks for the reduced test case!

@StephanTLavavej
Copy link
Member Author

Tracked by Microsoft-internal VSO-1287222 "[modules] transitive header unit imports do not import macros" and fixed by MSVC-PR-308046 in VS 2019 16.10 Preview 2.

@StephanTLavavej StephanTLavavej added the external This issue is unrelated to the STL label Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Compiler work involved external This issue is unrelated to the STL
Projects
None yet
Development

No branches or pull requests

2 participants