[cfe-dev] Declaration of MSVC internal functions

Francois Pichet pichet2000 at gmail.com
Wed Jan 19 05:46:49 PST 2011

On Wed, Jan 19, 2011 at 6:18 AM, Benoit Perrot <benoit at lrde.epita.fr> wrote:
> Hi,
> While experimenting with Clang and MSVC 9 (and among the different
> issues), including "iosfwd" generates the following error:

Currently clang cannot parse the templated MSVC C++ header files.
Maybe in 4-5 months it will.

> C:\Program Files\Microsoft Visual Studio 9.0\VC\include/iosfwd(219) :
> error: no member named '_invalid_parameter_noinfo' in the global namespace;
> did you mean '_invalid_parameter_handler'?
>                 _SCL_SECURE_CRT_VALIDATE(_Dest_size >= _Count, NULL);
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Yes i am very familiar with this problem. The reason is template
related. iosfwd line 219 is inside template code. MSVC does all
semantic analysis of template code at instantiation time. At this this
point the function _invalid_parameter_noinfo is not yet declared, but
it will get declared later.

> "iosfwd" uses "_SCL_SECURE_CRT_VALIDATE" which uses
> "_SCL_SECURE_INVALID_PARAMETER" which is defined as a call to
> "::_invalid_parameter_noinfo". Yet "::_invalid_parameter_noinfo" is
> declared nowhere in the translation unit; its declaration can be found
> in "Microsoft Visual Studio 9.0/VC/crt/src/internal.h". Including this
> file is not required by MSVC for compiling users of "iosfwd".

_invalid_parameter_noinfo is declared in file <xutility>, it is not a
builtin. MSVC doesn't generate an error is because the call in inside
a template definition,  MSVC doesn't do name resolution at template
definition, clang does because the function is not type dependent.
At template instantiation time, the function will be declared, hence
MSVC will find it.

> So, here is the question: shall this function (and the
> others that can be found in "internal.h") be considered as a builtin?

No because it is not an builtin.

> Adding it to "Basic/Builtins.def" as follows:
>        // Random Microsoft VC9 runtime builtins.
>        BUILTIN(_invalid_parameter_noinfo, "v.", "n")
> silences the error; but should'nt it be activated only when simulating
> Would'nt it be a better idea to silently include "crt/src/internal.h"
> when some appropriated cocktail of driver options are activated?

No we need a general solution to a general problem:

template <class T>
void foo() {
      func();   <== no type dependent function call. clang generates
an error, msvc doesn't

void func(){

int main() {

I got some ideas on how to solve that problem. I'll write a proposal
later. But the general idea is to postpone name lookup for
UnresolvedLookupExpr node to instantiation time in Microsoft mode.

More information about the cfe-dev mailing list