diff --git a/Modules/TestForANSIForScope.cmake b/Modules/TestForANSIForScope.cmake index 1224a21320..2b539fc8b0 100644 --- a/Modules/TestForANSIForScope.cmake +++ b/Modules/TestForANSIForScope.cmake @@ -5,14 +5,32 @@ TestForANSIForScope ------------------- -Check for ANSI for scope support +This module checks whether the ``CXX`` compiler restricts the scope of variables +declared in a for-init-statement to the loop body. In early C++ (pre-C++98), +variables declared in ``for( ...)`` could remain accessible +outside the loop after its body (``for() { }``). -Check if the compiler restricts the scope of variables declared in a -for-init-statement to the loop body. +This module defines the following cache variable: -:: +``CMAKE_NO_ANSI_FOR_SCOPE`` + A cache variable containing the result of the check. It will be set to value + ``0`` if the for-init-statement has restricted scope (``C++ 98`` and newer), + and to value ``1`` if not (``ANSI C++``). - CMAKE_NO_ANSI_FOR_SCOPE - holds result +.. note:: + + As of the ``C++ 98`` standard, variables declared in a for-init-statement are + restricted to the loop body, making this behavior obsolete. + +Examples +^^^^^^^^ + +Including this module will check the ``for()`` loop scope behavior and define +the ``CMAKE_NO_ANSI_FOR_SCOPE`` cache variable: + +.. code-block:: cmake + + include(TestForANSIForScope) #]=======================================================================] if(NOT DEFINED CMAKE_ANSI_FOR_SCOPE)