Declaration of MSVC internal functions

Hi,

While experimenting with Clang and MSVC 9 (and among the different
issues), including "iosfwd" generates the following error:

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);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from C:/tmp/test-iosfwd.cpp:1:
In file included from C:\Program Files\Microsoft Visual Studio 9.0\VC\include/iosfwd:6:
In file included from C:\Program Files\Microsoft Visual Studio 9.0\VC\include/cstdio:5:
C:\Program Files\Microsoft Visual Studio 9.0\VC\include/yvals.h:226:4: note:
instantiated from:

                         _SCL_SECURE_INVALID_PARAMETER(cond); \
                         ^
C:\Program Files\Microsoft Visual Studio 9.0\VC\include/yvals.h:183:47: note:
instantiated from:

#define _SCL_SECURE_INVALID_PARAMETER(expr) ::_invalid_parameter_noinfo()

(To the curious one: this is related to safety checks that where added
to common C runtime functions. MSDN says that defining the macro
"_CRT_SECURE_NO_DEPRECATE" silences the warnings related to the usage
of these "unsafe" functions -- but it does not fix the build with
Clang)

"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".

So, here is the question: shall this function (and the
others that can be found in "internal.h") be considered as a 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
MSVC?

Would'nt it be a better idea to silently include "crt/src/internal.h"
when some appropriated cocktail of driver options are activated?

Hi,
While experimenting with Clang and MSVC 9 (and among the different
issues), including "iosfwd" generates the following error:

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'?

So, here is the question: shall this function (and the
others that can be found in "internal.h") be considered as a 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
MSVC?

Probably.

Would'nt it be a better idea to silently include "crt/src/internal.h"
when some appropriated cocktail of driver options are activated?

The source for the runtime is not included with all the Visual Studio versions, especially not with the Express edition. Makes it a less good idea. :slight_smile:

Bo Persson

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, &quot;v\.&quot;, &quot;n&quot;\)

silences the error; but should'nt it be activated only when simulating
MSVC?

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() {
    foo<int>();
}

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.