Language element control
#pragma langlvl (C only)
Determines whether source code and compiler options should be checked for conformance to a specific language standard, or subset or superset of a standard.
Category: Language element control for C
.-,---------------------. V .-EXTENDED----------. | >>-LANG--(----+-COMMONC-----------+-+--)----------------------->< +-EXTC89------------+ +-EXTC99------------+ +-EXTC1X------------+ +-SAA---------------+ +-SAAL2-------------+ +-STDC89------------+ +-STDC99------------+ '-feature_suboption-'
Category: Language element control for C++
.-,---------------------. V .-EXTENDED----------. | >>-LANG--(----+-EXTENDED0X--------+-+--)----------------------->< +-COMPAT92----------+ +-STRICT98----------+ '-feature_suboption-'
LANGLVL(EXTENDED)
The following suboptions are only available under z/OS XL C:
The following suboptions are available under z/OS XL C and z/OS XL C++:
#ifdef __ANSI__
#define _Packed
#endif
The compiler will now see the _Packed attribute as a blank when LANGLVL(ANSI) is specified at compile time, and the language level of the code will be ANSI.
Predefined option groups are provided for commonly used settings for C++. These groups are:
The suboptions and their default settings for different language levels are listed in Table 1. The default setting On means that the suboption is enabled; otherwise, the default setting Off means that the suboption is disabled.
| Options | Group names | |||
|---|---|---|---|---|
| compat92 | strict98 / ansi | extended | extended0x | |
| KEYWORD(bool) | NOKEYWORD(bool) | Off | On | On | On |
| KEYWORD(explicit) | NOKEYWORD(explicit) | Off | On | On | On |
| KEYWORD(export) | NOKEYWORD(export) | Off | On | On | On |
| KEYWORD(false) | NOKEYWORD(false) | Off | On | On | On |
| KEYWORD(mutable) | NOKEYWORD(mutable) | Off | On | On | On |
| KEYWORD(namespace) | NOKEYWORD(namespace) | Off | On | On | On |
| KEYWORD(true) | NOKEYWORD(true) | Off | On | On | On |
| KEYWORD(typename) | NOKEYWORD(typename) | Off | On | On | On |
| KEYWORD(using) | NOKEYWORD(using) | Off | On | On | On |
| LANGLVL(ANONSTRUCT | NOANONSTRUCT) | Off | Off | On | On |
| LANGLVL(ANONUNION | NOANONUNION) | On | Off | On | On |
| LANGLVL(ANSIFOR | NOANSIFOR) | Off | On | On | On |
| LANGLVL(ANSISINIT | NOANSISINIT) | Off | On | On | On |
| LANGLVL(AUTOTPYEDEDUCTION | NOAUTOTPYEDEDUCTION) | Off | Off | Off | On |
| LANGLVL(C1XNORETURN | NOC1XNORETURN) | Off | Off | On | On |
| LANGLVL(C99__FUNC__ | NOC99__FUNC__) | Off | Off | On | On |
| LANGLVL(C99COMPLEX | NOC99COMPLEX) | Off | Off | Off | Off |
| LANGLVL(C99COMPLEXHEADER | NOC99COMPLEXHEADER) | Off | Off | Off | Off |
| LANGLVL(C99LONGLONG | NOC99LONGLONG) | Off | Off | Off | On |
| LANGLVL(C99PREPROCESSOR | NOPREPROCESSOR) | Off | Off | Off | On |
| LANGLVL(C99VLA | NOC99VLA) | Off | Off | On | On |
| LANGLVL(COMPATRVALUEBINDING | NOCOMPATRVALUEBINDING) | Off | Off | Off | Off |
| LANGLVL(COMPLEXINIT | NOCOMPLEXINIT) | Off | Off | On | On |
| LANGLVL(CONSTEXPR | NOCONSTEXPR) | Off | Off | Off | On |
| LANGLVL(DECLTYPE | NODECLTYPE) | Off | Off | Off | On |
| LANGLVL(DEFAULTANDDELETE | NODEFAULTANDDELETE) | Off | Off | Off | On |
| LANGLVL(DELEGATINGCTORS | NODELEGATINGCTORS) | Off | Off | Off | On |
| LANGLVL(DEPENDENTBASELOOKUP | NODEPENDENTBASELOOKUP) | On | On | On | Off |
| LANGLVL(EMPTYSTRUCT | NOEMPTYSTRUCT) | On | Off | On | On |
| LANGLVL(EXPLICITCONVERSIONOPERATORS | NOEXPLICITCONVERSIONOPERATORS) | Off | Off | Off | On |
| LANGLVL(EXTENDEDFRIEND | NOEXTENDEDFRIEND) | Off | Off | Off | On |
| LANGLVL(EXTENDEDINTEGERSAFE | NOEXTENDEDINTEGERSAFE) | Off | Off | Off | Off |
| LANGLVL(EXTERNTEMPLATE | NOEXTERNTEMPLATE) | Off | Off | On | On |
| LANGLVL(GNU_COMPLEX | NOGNU_COMPLEX) | Off | Off | Off | Off |
| LANGLVL(GNU_COMPUTEDGOTO | NOGNU_COMPUTEDGOTO) | Off | Off | On | On |
| LANGLVL(GNU_INCLUDE_NEXT | NOGNU_INCLUDE_NEXT) | On | On | On | On |
| LANGLVL(GNU_LABELVALUE | NOGNU_LABELVALUE) | Off | Off | On | On |
| LANGLVL(GNU_SUFFIXIJ | NOGNU_SUFFIXIJ) | Off | Off | On | On |
| LANGLVL(ILLPTOM | NOILLPTOM) | On | Off | On | On |
| LANGLVL(IMPLICITINT | NOIMPLICITINT) | On | Off | On | On |
| LANGLVL(INLINENAMESPACE | NOINLINENAMESPACE) | Off | Off | Off | On |
| LANGLVL(LIBEXT | NOLIBEXT) | On | Off | On | On |
| LANGLVL(LONGLONG | NOLONGLONG) | On | Off | On | Off |
| LANGLVL(OFFSETNONPOD | NOOFFSETNONPOD) | On | Off | On | On |
| LANGLVL(OLDDIGRAPH | NOOLDDIGRAPH) | Off | On | Off | Off |
| LANGLVL(OLDFRIEND | NOOLDFRIEND) | On | Off | On | Off |
| LANGLVL(OLDMATH | NOOLDMATH) | On | Off | Off | Off |
| LANGLVL(OLDSTR | NOOLDSTR) | On | Off | Off | Off |
| LANGLVL(OLDTEMPACC | NOOLDTEMPACC) | On | Off | On | On |
| LANGLVL(OLDTMPLALIGN | NOOLDTMPLALIGN) | On | Off | Off | Off |
| LANGLVL(OLDTMPLSPEC | NOOLDTMPLSPEC) | On | Off | On | On |
| LANGLVL(REDEFMAC | NOREDEFMAC) | Off | Off | Off | Off |
| LANGLVL(REFERENCECOLLAPSING | NOREFERENCECOLLAPSING) | Off | Off | Off | On |
| LANGLVL(RIGHTANGLEBRACKET | NORIGHTANGLEBRACKET) | Off | Off | Off | On |
| LANGLVL(RVALUEREFERENCES | NORVALUEREFERENCES) | Off | Off | Off | On |
| LANGLVL(SCOPEDENUM | NOSCOPEDENUM) | Off | Off | Off | On |
| LANGLVL(STATIC_ASSERT | NOSTATIC_ASSERT) | Off | Off | Off | On |
| LANGLVL(TEMPSASLOCALS | NOTEMPSASLOCALS) | Off | Off | Off | Off |
| LANGLVL(TEXTAFTERENDIF | NOTEXTAFTERENDIF) | Off | Off | Off | Off |
| LANGLVL(TRAILENUM | NOTRAILENUM) | On | Off | On | On |
| LANGLVL(TYPEDEFCLASS | NOTYPEDEFCLASS) | On | Off | On | On |
| LANGLVL(VARIADICTEMPLATES | NOVARIADICTEMPLATES) | Off | Off | Off | On |
| LANGLVL(VARARGMACROS | NOVARARGMACROS) | Off | Off | On | On |
| LANGLVL(ZEROEXTARRAY | NOZEROEXTARRAY) | Off | Off | On | On |
| RTTI | NORTTI | Off | On | On | On |
| TMPLPARSE(NO | ERROR | WARN) | NO | WARN | NO | NO |
The following suboptions are only available under z/OS XL C++:
Example: Anonymous structs typically are used in unions, as in the following code example:
union U {
struct {
int i:16;
int j:16;
};
int k;
} u;
// ...
u.j=3;
When LANG(ANONSTRUCT) is in effect, you receive
a warning if your code declares an anonymous struct. You can suppress
the warning with SUPPRESS(CCN5017). When you build with LANG(NOANONSTRUCT)
an anonymous struct is flagged as an error. Specify LANG(NOANONSTRUCT)
for compliance with ISO standard C++. The default is LANG(ANONSTRUCT).Example: The following code causes a name lookup error:
{
//...
for (int i=1; i<5; i++) {
cout << i * 2 << endl;
}
i = 10; // error
}
The reason for the error is that i,
or any name declared within a for-init-statement, is visible only
within the for statement. To correct the error, either
declare i outside the loop or specify LANG(NOANSIFOR).
Specify LANG(NOANSIFOR) to allow old language behavior. The default
is LANG(ANSIFOR).If you specify the LP64 option and the LANGLVL(NOANSISINIT) option, the compiler issues a warning, ignores the LANGLVL(NOANSISINIT) option and turns on the LANGLVL(ANSISINIT) option.
The default setting is LANGLVL(ANSISINIT).
This option controls whether the auto type deduction feature
is enabled. When LANG(AUTOTYPEDEDUCTION) is in effect, you do not
need to specify a type when declaring a variable. Instead, the compiler
deduces the type of an auto variable from the type of its initializer
expression. When LANGLVL(AUTOTYPEDEDUCTION) is enabled, the macro __IBMCPP_AUTO_TYPEDEDUCTION is defined as 1; otherwise, the macro is undefined. In both cases, the macro is protected and a compiler warning is displayed if it is undefined or redefined.
LANGLVL(AUTOTYPEDEDUCTION) is implied in the group option of LANGLVL(EXTENDED0X). You can also use this group option to enable the auto type deduction feature.
The default is LANG(NOAUTOTYPEDEDUCTION).
When LANGLVL(C1XNORETURN) is enabled, the macro __IBMC_NORETURN is defined as 1.
LANGLVL(C1XNORETURN) is implied in group options LANGLVL(EXTENDED0X) and LANGLVL(EXTENDED). You can also use these group options to enable the function specifier.
The default is LANG(NOC1XNORETURN).
This option controls whether the feature of C99 long
long with IBM® extensions
adopted in C++11 is enabled. When LANG(C99LONGLONG) is in effect,
the C++ compiler provides the C99 long long with IBM extensions feature. Source compatibility
between the C and the C++ language is improved. The default is LANG(NOC99LONGLONG).
The C99LONGLONG option conflicts with the LONGLONG option. If you specify both options, the LONGLONG option is ignored.
This option controls whether the C99 preprocessor features
adopted in C++11 are enabled. When LANG(C99PREPROCESSOR) is in effect,
C99 and C++11 compilers provide a common preprocessor interface, which
can ease the porting of C source files to the C++ compiler and avoid
preprocessor compatibility issues. The default is LANG(NOC99PREPROCESSOR).
LANGLVL(COMPLEXINIT) is implied in group options LANGLVL(EXTENDED) and LANGLVL(EXTENDED0X), so you can also use these group options to enable the initialization of complex types.
Controls whether the generalized constant expressions feature
is enabled. When you specify the LANGLVL(CONSTEXPR) option, the compiler
extends the expressions permitted within constant expressions. A constant
expression is one that can be evaluated at compile time. The default
option is LANGLVL(NOCONSTEXPR).
This option controls whether the decltype specifier is enabled.
When LANG(DECLTYPE) is in effect, decltype can be used on an expression
to get the resultant type of that expression, which might be type
dependent. The default is LANG(NODECLTYPE).
Controls whether the defaulted and deleted functions feature
is enabled. With this feature, you can define explicitly defaulted
functions whose implementations are generated by the compiler to achieve
higher efficiency. You can also define deleted functions whose usages
are disabled by the compiler to avoid calling unwanted functions.
LANGLVL(DEFAULTANDDELETE) is implied in the group option of LANGLVL(EXTENDED0X).
You can also use this group option to enable the delegating constructors
feature. The default is LANGLVL(NODEFAULTANDDELETE).
This option controls whether the delegating constructors
feature is enabled. When LANG(DELEGATINGCTORS) is specified, you can
concentrate common initializations and post initializations in one
constructor, which improves the readability and maintainability of
the program. The default is LANG(NODELEGATINGCTORS). struct base
{
int baseName;
};
template <class B> struct derived : public B
{
void func()
{
int i = baseName; // this name will not be found in the base class
};
};
int main(void)
{
derived<base> x;
x.func();
return 0;
}
struct base
{
int baseName;
};
template <class B> struct derived : public B
{
void func()
{
int i = B::baseName; // qualified name will be found in the base class
};
};
int main(void)
{
derived<base> x;
x.func();
return 0;
}
The default is LANG(DEPENDENTBASELOOKUP). When the default
option is in effect, the behavior of previous XL C++ compilers remains.struct S {
; // this line is ill-formed
};
Compilation is based on the C++11 standard, invoking most
of the C++ features and all the currently-supported C++11 features.
Controls whether the explicit conversion operators feature
is enabled. When you specify the LANGLVL(EXPLICITCONVERSIONOPERATORS)
option, you can apply the explicit function specifier to the definition
of a user-defined conversion function, and thus to inhibit unintended
implicit conversions through the user-defined conversion function. The LANGLVL(EXPLICITCONVERSIONOPERATORS) option is included in the group option LANGLVL(EXTENDED0X), so you can also use this group option to enable the explicit conversion operators feature.
The default is LANG(NOEXPLICITCONVERSIONOPERATORS).
This option controls whether C++98 or C++11 friend declarations
are used. With this option, you can name template parameters and typedef names
as friends. Basic types can also be used in friend declarations in
the C++11 standard. The class keyword in the context
for friend declarations is removed in the C++11 standard, which differs
from the C++98 friend class declaration syntax where the class keyword
is necessary. This greatly improves the generality of templates and
friend declarations. The default is LANG(NOEXTENDEDFRIEND). The LANGLVL(EXTENDEDFRIEND) option is incompatible with the LANGLVL(OLDFRIEND) compiler option. When LANGLVL(EXTENDEDFRIEND) is in effect, the LANGLVL(OLDFRIEND) option is ignored and its setting is LANGLVL(NOOLDFRIEND).
With this option, if a decimal integer literal does not have
a suffix containing u or U and it
cannot be represented by the long long int type,
you can decide whether to use the unsigned long long int to
represent the literal. The default is LANG(NOEXTENDEDINTEGERSAFE). This option takes effect only when the LANG(C99LONGLONG) option is specified. Otherwise, the compiler issues a warning message to indicate that the option is ignored. When you specify both LANG(C99LONGLONG) and LANG(EXTENDEDINTEGERSAFE), if a decimal integer literal does not have a suffix containing u or U and it cannot be represented by the long long int type, the compiler issues an error message stating that the value of the literal is out of range.
This option controls whether the feature for supporting explicit
instantiation declarations is enabled. With this feature, you can
suppress the implicit instantiations of a template specialization
or its members. This feature can be enabled by LANG(EXTERNTEMPLATE),
which is the default. struct C {
void foo(init);
};
void (C::*p) (int) = C::foo;
struct C {
void foo(int);
};
void (C::*p) (int) = &C::foo;
MyFunction()
{
return 0;
}
int MyFunction()
{
return 0;
}
This option controls whether the inline namespace definition
feature is enabled. A namespace definition preceded by an initial inline keyword
is defined as an inline namespace. Members of the inline namespace
can be defined and specialized as if they were also members of the
enclosing namespace. The default is LANG(NOINLINENAMESPACE). friend IFont;
This
example declaration causes a warning unless you modify it or suppress
the message with the SUPPRESS(CCN5070) option. Specify LANG(NOOLDFRIEND) for
compliance with ISO standard C++. Specifying this option will
cause an error condition and message to be generated for the example
declaration. friend class IFont;
The default
for batch and TSO is LANG(OLDFRIEND).A number of the string function signatures that are defined in the 1989 C International Standard and the C Amendment are not const-safe.
char * strchr(const char *s, int c);
The behavior of this function is specified as follows:
Since the parameter s is of type const char *s, the string being searched by the strchr function is potentially composed of characters whose type is const char. The strchr function returns a pointer to one of the constituent characters of the string, but this pointer is of type char * even though the character that it points to is potentially of type const char. For this reason, strchr can be used to implicitly (and unintentionally) defeat the const-qualification of the string referenced by the pointer s.
const char * strchr(const char *s, int c);
char * strchr( char *s, int c);
Both of these overloaded functions have the same behavior as the original C version of strchr.
In a similar manner, the signatures of several other standard C library routines are replaced in the C++ standard. The affected routines are:
#include <string.h>
const char s[] = "foobar";
int main(void) {
char * c = strchr(s, 'b');
}
To preserve compatibility with earlier releases (and thus enable this code example), specify LANGLVL(OLDSTR).
class C {
public:
C(char *);
protected:
C(const C&);
};
C foo() {return C("test");} // returns a copy of a C object
void f()
{
// catch and throw both make implicit copies of the thrown object
throw C("error"); // throws a copy of a C object
const C& r = foo(); // uses the copy of a C object created by foo()
}
template<classT> class ribbon { /*...*/};
class ribbon<char> { /*...*/};
template<class T> class ribbon { /*...*/};
template<> class ribbon<char> { /*...*/};
The
default is LANG(OLDTMPLSPEC).
Controls whether the reference collapsing feature is enabled.
To enable this feature, specify the LANGLVL(REFERENCECOLLAPSING) option. The LANGLVL(REFERENCECOLLAPSING) option is included in the group option LANGLVL(EXTENDED0X), so you can also use this group option to enable the reference collapsing feature.
When the LANGLVL(RVALUEREFERENCES) option is in effect, but the LANGLVL(REFERENCECOLLAPSING) option is not in effect, the compiler behaves as if the LANGLVL(REFERENCECOLLAPSING) option were specified.
The default option is LANGLVL(NOREFERENCECOLLAPSING).
Controls whether the right angle bracket feature is enabled.
To enable this feature, you can specify the LANGLVL(RIGHTANGLEBRACKET)
option. The LANGLVL(RIGHTANGLEBRACKET) option is included in the group option LANGLVL(EXTENDED0X), so you can also use this group option to enable the right angle bracket feature.
The default option is LANGLVL(NORIGHTANGLEBRACKET).
Controls whether the rvalue references feature is enabled.
To enable this feature, specify the LANGLVL(RVALUEREFERENCES) option.
The LANGLVL(RVALUEREFERENCES) option is included in the group option LANGLVL(EXTENDED0X), so you can also use this group option to enable the rvalue references feature.
If both the LANGLVL(COMPATRVALUEBINDING) and LANGLVL(RVALUEREFERENCES) options are in effect, the compiler issues an error message.
The default option is LANGLVL(NORVALUEREFERENCES).
Controls whether the scoped enumeration feature is enabled.
To enable this feature, you can specify the LANGLVL(SCOPEDENUM) option. The LANGLVL(SCOPEDENUM) option is included in the group option LANGLVL(EXTENDED0X), so you can also use this group option to enable the scoped enumeration feature.
The default option is LANGLVL(NOSCOPEDENUM).
This option controls whether the static assertions feature
is enabled. When LANGLVL(STATIC_ASSERT) is set, a severe error message
for compile-time assertions is issued on failure. The default is LANG(NOSTATIC_ASSERT).
enum grain { wheat, barley, rye,, };
Specify
LANG(NOTRAILENUM) for compliance with the ISO C and C++ standards.
The default is LANG(TRAILENUM).
This option controls whether the variadic templates feature
is enabled. When LANGLVL(VARIADICTEMPLATES) is set, you can define
class and function templates that have any number (including zero)
of parameters. The default is LANG(NOVARIADICTEMPLATES).
This
option controls whether zero-extent arrays are allowed as the last
nonstatic data member in a structure definition. When LANG(ZEROEXTARRAY)
is in effect, z/OS XL C++ compiler
allows arrays with zero elements. This is an extension to the C++
standard. struct S1 { char a[0]; };
The LANGLVL option defines a macro that specifies a language level. You must then include this macro in your code to force conditional compilation; for example, with the use of #ifdef directives. You can write portable code if you correctly code the different parts of your program according to the language level. You use the macro in preprocessor directives in header files.
You can control individual language features in the z/OS V1R2 C++ compiler by using the LANGLVL and KEYWORD suboptions listed in Table 1. In order to conform to the ISO C++ standard, you may need to make a number of changes to your existing source code. These suboptions can help by breaking up the changes into smaller steps.
For the list of predefined macros related to language levels, see "Macros related to language levels" in z/OS XL C/C++ Language Reference.