Determines whether source code and compiler options should be checked for conformance to a specific language standard, or subset or superset of a standard.
-qlanglvl syntax — C .-:-----------------------. V .-extc99---. .-ucs---. | >>- -q--langlvl--=----+-classic--+--+-noucs-+-+---------------->< +-extc89---+ +-extended-+ +-saa------+ +-saal2----+ +-stdc89---+ '-stdc99---'
#pragma langlvl syntax — C only .-extc99---. >>-#--pragma--langlvl--(--+-classic--+--)---------------------->< +-extc89---+ +-extended-+ +-saa------+ +-saal2----+ +-stdc89---+ '-stdc99---'
-qlanglvl syntax — C++ .-:---------------------. .-extended---. V | >>- -q--langlvl--=--+-compat366--+------feature_suboption---+-->< +-extended0x-+ '-strict98---'
Options | Language levels | |||
---|---|---|---|---|
compat366 | strict98 | extended (C++) | extended0x | |
-qlanglvl=anonstruct | noanonstruct | Off | Off | On | On |
-qlanglvl=anonunion | noanonunion | On | Off | On | On |
-qlanglvl=ansifor | noansifor | Off | On | On | On |
-qlanglvl=ansisinit | noansisinit | On | On | On | On |
-qlanglvl=autotypededuction| noautotypededuction | Off | Off | Off | On |
-qlanglvl=c99__func__ | noc99__func__ | Off | Off | On | On |
-qlanglvl=c99complex |noc99complex | Off | Off | Off | Off |
-qlanglvl=c99complexheader | noc99complexheader | Off | Off | Off | Off |
-qlanglvl=c99compoundliteral | noc99compoundliteral | Off | Off | On | On |
-qlanglvl=c99hexfloat | noc99hexfloat | Off | Off | On | On |
-qlanglvl=c99longlong | noc99longlong | Off | Off | Off | On |
-qlanglvl=c99preprocessor | noc99preprocessor | Off | Off | Off | On |
-qlanglvl=c99vla | noc99vla | Off | Off | On | On |
-qlanglvl=compatzea | nocompatzea | Off | Off | Off | Off |
-qlanglvl=decltype | nodecltype | Off | Off | Off | On |
-qlanglvl=delegatingctors | nodelegatingctors | Off | Off | Off | On |
-qlanglvl=dependentbaselookup | nodependentbaselookup | On | On | On | Off |
-qlanglvl=emptystruct | noemptystruct | On | On | On | On |
-qlanglvl=extendedfriend | noextendedfriend | Off | Off | Off | On |
-qlanglvl=extendedintegersafe | noextendedintegersafe | Off | Off | Off | Off |
-qlanglvl=externtemplate | noexterntemplate | Off | Off | On | On |
-qlanglvl=FileScopeConstExternLinkage | noFileScopeConstExternLinkage | Off | Off | Off | Off |
-qlanglvl=inlinenamespace | noinlinenamespace | Off | Off | Off | On |
-qlanglvl=gnu_assert | nognu_assert | Off | Off | On | On |
-qlanglvl=gnu_complex | nognu_complex | Off | Off | Off | Off |
-qlanglvl=gnu_computedgoto | nognu_computedgoto | Off | Off | On | On |
-qlanglvl=gnu_explicitregvar | nognu_explicitregvar | Off | Off | On | On |
-qlanglvl=gnu_externtemplate | nognu_externtemplate | Off | Off | On | On |
-qlanglvl=gnu_labelvalue | nognu_labelvalue | Off | Off | On | On |
-qlanglvl=gnu_locallabel | nognu_locallabel | Off | Off | On | On |
-qlanglvl=gnu_include_next | nognu_include_next | On | On | On | On |
-qlanglvl=gnu_membernamereuse | nognu_membernamereuse | Off | Off | On | On |
-qlanglvl=gnu_suffixij | nognu_suffixij | Off | Off | On | On |
-qlanglvl=gnu_varargmacros | nognu_varargmacros | Off | Off | On | On |
-qlanglvl=gnu_warning | nognu_warning | Off | Off | On | On |
-qlanglvl=illptom | noillptom | On | Off | On | On |
-qlanglvl=implicitint | noimplicitint | On | Off | On | On |
-qlanglvl=newexcp | nonewexcp | Off | Off | Off | Off |
-qlanglvl=offsetnonpod | nooffsetnonpod | On | Off | On | On |
-qlanglvl=olddigraph | noolddigraph | Off | On | Off | Off |
-qlanglvl=oldfriend | nooldfriend | On | Off | On | Off |
-qlanglvl=oldmath | nooldmath | On | Off | Off | Off |
-qlanglvl=oldtempacc | nooldtempacc | On | Off | On | On |
-qlanglvl=oldtmplalign | nooldtmplalign | On | Off | Off | Off |
-qlanglvl=oldtmplspec | nooldtmplspec | On | Off | On | On |
-qlanglvl=redefmac | noredefmac | Off | Off | Off | Off |
-qlanglvl=static_assert | nostatic_assert | Off | Off | Off | On |
-qlanglvl=trailenum | notrailenum | On | Off | On | On |
-qlanglvl=typedefclass | notypedefclass | On | Off | On | On |
-qlanglvl=noucs | nonoucs | Off | Off | Off | Off |
-qlanglvl=varargmacros | novarargmacros | Off | Off | On | On |
-qlanglvl=variadic[templates] | novariadic[templates] | Off | Off | Off | On |
-qlanglvl=zeroextarray | nozeroextarray | Off | Off | On | On |
The following outlines the differences between the classic language level and all other standard-based language levels:
For similar reasons, tokens separated only by a comment may also be combined to form a single token. Here is a summary of how tokenization of a program compiled in classic mode is performed:
It is in the third and fourth steps that the text of adjacent but previously separate tokens may be combined to form new tokens.
The \ character for line continuation is accepted only in string and character literals and on preprocessing directives.
Constructs such as:
#if 0 “unterminated #endif #define US ”Unterminating string char *s = US terminated now“
will not generate diagnostic messages, since the first is an unterminated literal in a FALSE block, and the second is completed after macro expansion. However:
char *s = US;
will generate a diagnostic message since the string literal in US is not completed before the end of the line.
Empty character literals are allowed. The value of the literal is zero.
#define f(a,b) a+b f\ (1,2) /* accepted */
#define f(a,b) a+b f(\ 1,2) /* not accepted */
The rules concerning \ apply whether or not the directive is valid. For example,
#\ define M 1 /* not allowed */
#def\ ine M 1 /* not allowed */
#define\ M 1 /* allowed */
#dfine\ M 1 /* equivalent to #dfine M 1, even though #dfine is not valid */
Following are the preprocessor directive differences.
For an invalid parameter list, a warning is issued. If a macro name is redefined with a new definition, a warning will be issued and the new definition used.
#define M() 1 #define N(a) (a) #define O(a,b) ((a) + (b))
M(); /* no error */ N(); /* empty argument */ O(); /* empty first argument and too few arguments */
union U { struct { int i:16; int j:16; }; int k; } u; // ... u.j=3;When the default, -qlanglvl=anonstruct, is in effect, anonymous structures are supported.
This is an extension to the C++ standard and gives behavior that is designed to be compatible with Microsoft® Visual C++. Specify -qlanglvl=noanonstruct for compliance with standard C++.
This is an extension to standard C++ and gives behavior that is designed to be compatible with previous versions of VisualAge® C++ and predecessor products, and Microsoft Visual C++. Specify -qlanglvl=noanonunion for compliance with standard C++.
{ //... 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 loop initialization statement, is visible only within the for statement. To correct the error, either declare i outside the loop or set noansifor.
When -qlanglvl=noansifor is in effect, the old language behavior is used; specify -qlanglvl=noansifor for compatibility with earlier versions of VisualAge C++ and predecessor products, and Microsoft Visual C++.
When -qlanglvl=noansisinit is in effect, the old language behavior is used; specify -qlanglvl=noansisinit for compatibility with earlier versions of VisualAge C++ and predecessor products.
The -qlanglvl=autotypededuction option is included in the group option -qlanglvl=extended0x.
The default option is -qlanglvl=noautotypededuction.
The -qlanglvl=c99longlong option conflicts with the -qlonglong option. If you specify both these two options, the -qlonglong option is ignored. For more information about the -qlonglong option, see -qlonglong.
The -qlanglvl=c99longlong option is included in the group option -qlanglvl=extended0x, so you can also use this group option to enable the C99 long long feature.
The default option is -qlanglvl=noc99longlong.
The default option is -qlanglvl=noc99preprocessor.
The -qlanglvl=decltype option is included in the group option -qlanglvl=extended0x, so you can also use this group option to enable the decltype feature.
The default option is -qlanglvl=nodecltype.
The -qlanglvl=delegatingctors option is included in the group option -qlanglvl=extended0x, so you can also use this group option to enable the delegating constructors feature.
The default option is -qlanglvl=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; }
struct S { ; // this line is ill-formed };
The default is -qlanglvl=noemptystruct.
The -qlanglvl=extendedfriend option is included in the group option -qlanglvl=extended0x.
The default option is -qlanglvl=noextendedfriend.
This option takes effect only when the -qlanglvl=c99longlong option is specified, otherwise, the compiler issues a warning message to indicate that the option is ignored. When you specify both the -qlanglvl=c99longlong and -qlanglvl=extendedintegersafe options, if a decimal integer literal that does not have a suffix containing u or U 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.
The default option is -qlanglvl=noextendedintegersafe in all the language levels.
The -qlanglvl=externtemplate option is included in the group options of -qlanglvl=extended and -qlanglvl=extended0x, so you can use these two group options to enable this feature.
Option | Description |
---|---|
-qtemplateregistry, -qtempinc | Explicit instantiation declarations remain effective. Referenced specializations that are the subjects of explicit instantiation declarations, but not the subjects of explicit instantiation definitions in a translation unit are not instantiated from or because of that translation unit. |
IBM language extension | Description |
---|---|
#pragma instantiate | This pragma is semantically the same as an explicit instantiation definition. |
#pragma do_not_instantiate | This pragma provides a subset of the functionality of the explicit instantiation declarations which is introduced in the C++0x standard. It is provided for backwards compatibility purposes only. New applications can use explicit instantiation declarations. |
#pragma hashome, #pragma ishome | This pragma causes the generation of the virtual function table (VFT) for a class template specialization irrespective of explicit instantiation declarations of the specialization. |
The -qlanglvl=[no]externtemplate option replaces the deprecated -qlanglvl=[no]gnu_externtemplate option. Use the -qlanglvl=[no]externtemplate option in your applications.
When -qlanglvl=FileScopeConstExternLinkage is in effect, all file scope constant variables are marked as externally visible. Otherwise, all file scope constant variables are marked as static.
The default is -qlanglvl=noFileScopeConstExternLinkage.
struct C { void foo(int); }; void (C::*p) (int) = C::foo;
This is an extension to standard C++ and gives behavior that is designed to be compatible with earlier versions of VisualAge C++ and its predecessor products, and Microsoft Visual C++.
Specify -qlanglvl=noillptom for compliance with the C++ standard. The example code above must be modified to use the & operator.
struct C { void foo(int); }; void (C::*p) (int) = &C::foo;
The following specifiers do not completely specify a type:
C++0x has removed the use of auto as a storage class specifier. In C++0x, the keyword auto is used as a type specifier. The compiler deduces the type of an auto variable from the type of its initializer expression. For more information, see The auto type specifier (C++0x).
For example, the return type of function MyFunction is int because it was omitted in the following code:
MyFunction() { return 0; }
Note that any situation where a type is specified is affected by this suboption. This includes, for example, template and parameter types, exception specifications, types in expressions (eg, casts, dynamic_cast, new), and types for conversion functions.
This is an extension to the C++ standard and gives behavior that is designed to be compatible with earlier versions of VisualAge C++ and predecessor products, and Microsoft Visual C++.
Specify -qlanglvl=noimplicitint for compliance with standard C++. For example, the function declaration above must be modified to:
int MyFunction() { return 0; }
The -qlanglvl=inlinenamespace option is included in the group option -qlanglvl=extended0x.
The default option is -qlanglvl=noinlinenamespace.
This suboption does not apply to the nothrow versions of the new operator, new operators with empty throw specifications, class-specific new operators, and new operators with placement arguments.
This is an extension to the C++ standard, and gives behavior that is designed to be compatible with VisualAge C++ for OS/2® 3.0, VisualAge for C++ for Windows®, V3.5, and Microsoft Visual C++. Specify -qlanglvl=nooffsetnonpod for compliance with standard C++.
Specify -qlanglvl=noolddigraph for compatibility with standard C++ and the extended C++ language level supported by previous versions of VisualAge C++ and predecessor products.
This suboption only has effect when -qdigraphs is in effect.
friend IFont;
This is an extension to the C++ standard and gives behavior that is designed to be compatible with earlier versions of VisualAge C++ and predecessor products, and Microsoft Visual C++.
Specify the -qlanglvl=nooldfriend for compliance with standard C++. The example declaration above must be modified to the following:
friend class IFont;
Specify -qlanglvl=nooldmath for strict compliance with the C++ standard. Specify -qlanglvl=oldmath for compatibility with earlier versions of VisualAge C++ and predecessor products.
class C { public: C(char *); protected: C(const C&); }; C foo() {return C(“test”);} // return copy of C object
void f() { // catch and throw both make implicit copies of // the throw object throw C(“error”); // throw a copy of a C object const C& r = foo(); // use the copy of a C object // created by foo() }The example code above contains three ill formed uses of the copy constructor C(const C&).
template <class T> struct A { #pragma options align=packed struct B { T m; int m2; }; #pragma options align=reset };Specify -qlanglvl=oldtmplalign for compatibility with VisualAge for C++ V4.0 and predecessor products.
template<class T> class ribbon { /*...*/}; class ribbon<char> { /*...*/};This is an extension to standard C++ and gives behavior that is designed to be compatible with VisualAge C++ for OS/2 3.0, VisualAge for C++ for Windows, V3.5, and Microsoft Visual C++.
Specify -qlanglvl=nooldtmplspec for compliance with standard C++. In the example above, the template specialization must be modified to:
template<class T> class ribbon { /*...*/}; template<> class ribbon<char> { /*...*/};
enum grain { wheat, barley, rye,, };
This is an extension to the C++ standard, and is intended to provide compatibility with Microsoft Visual C++.
Specify -qlanglvl=notrailenum for compliance with standard C++.
The -qlanglvl=variadic[templates] option is included in the group option -qlanglvl=extended0x, so you can also use this group option to enable the variadic templates feature.
The default option is -qlanglvl=novariadic[templates].
struct S1 { char a[0]; }; struct S2 { char b[]; };
This is an extension to the C++ standard, and is intended to provide compatibility with Microsoft Visual C++.
Specify -qlanglvl=nozeroextarray for compliance with standard C++ or with the ANSI language level supported by previous versions of VisualAge C++ and predecessor products.
Since the pragma directive makes your code non-portable, it is recommended that you use the option rather than the pragma. If you do use the pragma, it must appear before any noncommentary lines in the source code. Also, because the directive can dynamically alter preprocessor behavior, compiling with the preprocessing-only options may produce results different from those produced during regular compilation.
See Macros related to language levels for a list of macros that are predefined by -qlanglvl suboptions.