diff --git a/CMakeLists.txt b/CMakeLists.txt index ab70f1dab61..b956f4a68bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN "Set to ON to force using an old, unsupported host toolchain." OFF) + option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF) include(AddLLVM) include(TableGen) @@ -115,6 +116,19 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} ) if(LLVM_INCLUDE_TESTS) + set(Python_ADDITIONAL_VERSIONS 2.7) + include(FindPythonInterp) + if(NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR +"Unable to find Python interpreter, required for builds and testing. + +Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") + endif() + + if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) + message(FATAL_ERROR "Python 2.7 or newer is required") + endif() + # Check prebuilt llvm/utils. if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX} @@ -167,7 +181,7 @@ else() set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}") endif() -find_package(LibXml2) +find_package(LibXml2 2.5.3 QUIET) if (LIBXML2_FOUND) set(CLANG_HAVE_LIBXML 1) endif() @@ -252,7 +266,10 @@ configure_file( # Add appropriate flags for GCC if (LLVM_COMPILER_IS_GCC_COMPATIBLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -fno-strict-aliasing") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual") + if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") + endif () # Enable -pedantic for Clang even if it's not enabled for LLVM. if (NOT LLVM_ENABLE_PEDANTIC) @@ -331,6 +348,10 @@ macro(set_clang_windows_version_resource_properties name) endif() endmacro() +macro(add_clang_subdirectory name) + add_llvm_subdirectory(CLANG TOOL ${name}) +endmacro() + macro(add_clang_library name) cmake_parse_arguments(ARG "" @@ -358,7 +379,7 @@ macro(add_clang_library name) set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON) if(headers OR tds) - set(srcs ${headers} ${tds}) + set(srcs ${headers} ${tds}) endif() endif() endif(MSVC_IDE OR XCODE) @@ -397,6 +418,12 @@ macro(add_clang_executable name) set_clang_windows_version_resource_properties(${name}) endmacro(add_clang_executable) +macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets + llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) +endmacro() + set(CMAKE_INCLUDE_CURRENT_DIR ON) include_directories(BEFORE @@ -467,6 +494,10 @@ set(LIBCLANG_LIBRARY_VERSION "Version number that will be placed into the libclang library , in the form XX.YY") mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION) +option(CLANG_INCLUDE_TESTS + "Generate build targets for the Clang unit tests." + ${LLVM_INCLUDE_TESTS}) + add_subdirectory(utils/TableGen) add_subdirectory(include) @@ -487,10 +518,6 @@ else() endif() add_subdirectory(examples) -option(CLANG_INCLUDE_TESTS - "Generate build targets for the Clang unit tests." - ${LLVM_INCLUDE_TESTS}) - if( CLANG_INCLUDE_TESTS ) if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h) add_subdirectory(unittests) @@ -527,7 +554,8 @@ endif() set(CLANG_ORDER_FILE "" CACHE FILEPATH "Order file to use when compiling clang in order to improve startup time.") -if (CLANG_BUILT_STANDALONE) +if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR + CMAKE_VERSION VERSION_GREATER 3) # Generate a list of CMake library targets so that other CMake projects can # link against them. LLVM calls its version of this file LLVMExports.cmake, but # the usual CMake convention seems to be ${Project}Targets.cmake. @@ -551,3 +579,92 @@ if (CLANG_BUILT_STANDALONE) ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake COPYONLY) endif () + +if (CLANG_ENABLE_BOOTSTRAP) + include(ExternalProject) + + if(CMAKE_VERSION VERSION_GREATER 3.1.0) + set(cmake_3_1_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL 1) + endif() + + if(CMAKE_VERSION VERSION_GREATER 3.3.20150708) + set(cmake_3_4_USES_TERMINAL_OPTIONS + USES_TERMINAL_CONFIGURE 1 + USES_TERMINAL_BUILD 1 + USES_TERMINAL_INSTALL 1 + ) + set(cmake_3_4_USES_TERMINAL USES_TERMINAL 1) + endif() + + set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/bootstrap-stamps/) + set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/bootstrap-bins/) + + # If on Darwin we need to make bootstrap depend on LTO and pass + # DARWIN_LTO_LIBRARY so that -flto will work using the just-built compiler + if(APPLE) + set(LTO_DEP LTO llvm-ar llvm-ranlib) + set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib) + set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar) + set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib) + endif() + + add_custom_target(bootstrap-clear + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/bootstrap-cleared + ) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/bootstrap-cleared + DEPENDS clang ${LTO_DEP} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR} + COMMENT "Clobberring bootstrap build and stamp directories" + ) + + ExternalProject_Add(bootstrap + DEPENDS clang ${LTO_DEP} + PREFIX bootstrap + SOURCE_DIR ${CMAKE_SOURCE_DIR} + STAMP_DIR ${STAMP_DIR} + BINARY_DIR ${BINARY_DIR} + ${cmake_3_1_EXCLUDE_FROM_ALL} + CMAKE_ARGS + # We shouldn't need to set this here, but INSTALL_DIR doesn't + # seem to work, so instead I'm passing this through + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + ${CLANG_BOOTSTRAP_CMAKE_ARGS} + -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++ + -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang + -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang + ${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} + INSTALL_COMMAND "" + STEP_TARGETS configure build + ${cmake_3_4_USES_TERMINAL_OPTIONS} + ) + + # exclude really-install from main target + set_target_properties(bootstrap PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On) + ExternalProject_Add_Step(bootstrap really-install + COMMAND ${CMAKE_COMMAND} --build --target install + COMMENT "Performing install step for 'bootstrap'" + DEPENDEES build + ${cmake_3_4_USES_TERMINAL} + ) + ExternalProject_Add_StepTargets(bootstrap really-install) + add_custom_target(bootstrap-install DEPENDS bootstrap-really-install) + + + set(ADDITIONAL_TARGETS_TO_ADD check-llvm check-clang check-all) + foreach(target ${ADDITIONAL_TARGETS_TO_ADD}) + # exclude from main target + set_target_properties(bootstrap PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On) + + ExternalProject_Add_Step(bootstrap ${target} + COMMAND ${CMAKE_COMMAND} --build --target ${target} + COMMENT "Performing ${target} for 'bootstrap'" + DEPENDEES configure + ${cmake_3_4_USES_TERMINAL} + ) + ExternalProject_Add_StepTargets(bootstrap ${target}) + endforeach() +endif() diff --git a/CODE_OWNERS.TXT b/CODE_OWNERS.TXT index 905303fe11c..21962ca3382 100644 --- a/CODE_OWNERS.TXT +++ b/CODE_OWNERS.TXT @@ -33,6 +33,10 @@ N: Reid Kleckner E: rnk@google.com D: Microsoft C++ ABI compatibility and general Windows support +N: Manuel Klimek +E: klimek@google.com +D: AST matchers, LibTooling + N: Anton Korobeynikov E: anton@korobeynikov.info D: Exception handling, Windows codegen, ARM EABI @@ -45,10 +49,6 @@ N: John McCall E: rjmccall@apple.com D: Clang LLVM IR generation -N: Chad Rosier -E: mcrosier@codeaurora.org -D: Compiler driver - N: Richard Smith E: richard@metafoo.co.uk D: All parts of Clang not covered by someone else diff --git a/INSTALL.txt b/INSTALL.txt index bd2f4fe3709..a1652b243ee 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -44,6 +44,6 @@ From inside the Clang build directory, run 'make install' to install the Clang compiler and header files into the prefix directory selected when LLVM was configured. -The Clang compiler is available as 'clang' and 'clang++'. It supports a gcc like command line -interface. See the man page for clang (installed into $prefix/share/man/man1) -for more information. +The Clang compiler is available as 'clang' and 'clang++'. It supports a gcc like +command line interface. See the man page for clang (installed into +$prefix/share/man/man1) for more information. diff --git a/Makefile b/Makefile index bbc521f4c0e..9497b0a4219 100644 --- a/Makefile +++ b/Makefile @@ -67,8 +67,11 @@ endif # http://gcc.gnu.org/PR41874 # http://gcc.gnu.org/PR41838 # -# We can revisit this when LLVM/Clang support it. +# We don't need to do this if the host compiler is clang. +ifneq ($(CXX_COMPILER), "clang") CXX.Flags += -fno-strict-aliasing +endif + # Set up Clang's tblgen. ifndef CLANG_TBLGEN diff --git a/README.txt b/README.txt index 474c67cf59e..ada9ebc9e23 100644 --- a/README.txt +++ b/README.txt @@ -20,7 +20,7 @@ Information on the LLVM project: http://llvm.org/ If you have questions or comments about Clang, a great place to discuss them is on the Clang development mailing list: - http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev + http://lists.llvm.org/mailman/listinfo/cfe-dev If you find a bug in Clang, please file it in the LLVM bug tracker: http://llvm.org/bugs/ diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index f5caca8572c..49b2fd873f9 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -1100,6 +1100,8 @@ def __repr__(self): CursorKind.CUDAHOST_ATTR = CursorKind(415) CursorKind.CUDASHARED_ATTR = CursorKind(416) +CursorKind.VISIBILITY_ATTR = CursorKind(417) + ### # Preprocessing CursorKind.PREPROCESSING_DIRECTIVE = CursorKind(500) @@ -1162,12 +1164,36 @@ def is_definition(self): """ return conf.lib.clang_isCursorDefinition(self) + def is_const_method(self): + """Returns True if the cursor refers to a C++ member function or member + function template that is declared 'const'. + """ + return conf.lib.clang_CXXMethod_isConst(self) + + def is_mutable_field(self): + """Returns True if the cursor refers to a C++ field that is declared + 'mutable'. + """ + return conf.lib.clang_CXXField_isMutable(self) + + def is_pure_virtual_method(self): + """Returns True if the cursor refers to a C++ member function or member + function template that is declared pure virtual. + """ + return conf.lib.clang_CXXMethod_isPureVirtual(self) + def is_static_method(self): """Returns True if the cursor refers to a C++ member function or member function template that is declared 'static'. """ return conf.lib.clang_CXXMethod_isStatic(self) + def is_virtual_method(self): + """Returns True if the cursor refers to a C++ member function or member + function template that is declared 'virtual'. + """ + return conf.lib.clang_CXXMethod_isVirtual(self) + def get_definition(self): """ If the cursor is a reference to a declaration or a declaration of @@ -2877,6 +2903,14 @@ def cursor(self): [Index, c_char_p], c_object_p), + ("clang_CXXField_isMutable", + [Cursor], + bool), + + ("clang_CXXMethod_isConst", + [Cursor], + bool), + ("clang_CXXMethod_isPureVirtual", [Cursor], bool), diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py index a5224aafabc..c5ea50516ad 100644 --- a/bindings/python/tests/cindex/test_cursor.py +++ b/bindings/python/tests/cindex/test_cursor.py @@ -97,6 +97,36 @@ def test_canonical(): assert len(cursors) == 3 assert cursors[1].canonical == cursors[2].canonical +def test_is_const_method(): + """Ensure Cursor.is_const_method works.""" + source = 'class X { void foo() const; void bar(); };' + tu = get_tu(source, lang='cpp') + + cls = get_cursor(tu, 'X') + foo = get_cursor(tu, 'foo') + bar = get_cursor(tu, 'bar') + assert cls is not None + assert foo is not None + assert bar is not None + + assert foo.is_const_method() + assert not bar.is_const_method() + +def test_is_mutable_field(): + """Ensure Cursor.is_mutable_field works.""" + source = 'class X { int x_; mutable int y_; };' + tu = get_tu(source, lang='cpp') + + cls = get_cursor(tu, 'X') + x_ = get_cursor(tu, 'x_') + y_ = get_cursor(tu, 'y_') + assert cls is not None + assert x_ is not None + assert y_ is not None + + assert not x_.is_mutable_field() + assert y_.is_mutable_field() + def test_is_static_method(): """Ensure Cursor.is_static_method works.""" @@ -113,6 +143,36 @@ def test_is_static_method(): assert foo.is_static_method() assert not bar.is_static_method() +def test_is_pure_virtual_method(): + """Ensure Cursor.is_pure_virtual_method works.""" + source = 'class X { virtual void foo() = 0; virtual void bar(); };' + tu = get_tu(source, lang='cpp') + + cls = get_cursor(tu, 'X') + foo = get_cursor(tu, 'foo') + bar = get_cursor(tu, 'bar') + assert cls is not None + assert foo is not None + assert bar is not None + + assert foo.is_pure_virtual_method() + assert not bar.is_pure_virtual_method() + +def test_is_virtual_method(): + """Ensure Cursor.is_virtual_method works.""" + source = 'class X { virtual void foo(); void bar(); };' + tu = get_tu(source, lang='cpp') + + cls = get_cursor(tu, 'X') + foo = get_cursor(tu, 'foo') + bar = get_cursor(tu, 'bar') + assert cls is not None + assert foo is not None + assert bar is not None + + assert foo.is_virtual_method() + assert not bar.is_virtual_method() + def test_underlying_type(): tu = get_tu('typedef int foo;') typedef = get_cursor(tu, 'foo') diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py index f3dadf999bd..f2184338be4 100644 --- a/bindings/python/tests/cindex/test_type.py +++ b/bindings/python/tests/cindex/test_type.py @@ -134,7 +134,7 @@ def test_equal(): def test_type_spelling(): """Ensure Type.spelling works.""" - tu = get_tu('int c[5]; int i[]; int x; int v[x];') + tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];') c = get_cursor(tu, 'c') i = get_cursor(tu, 'i') x = get_cursor(tu, 'x') @@ -253,7 +253,7 @@ def test_function_variadic(): def test_element_type(): """Ensure Type.element_type works.""" - tu = get_tu('int c[5]; int i[]; int x; int v[x];') + tu = get_tu('int c[5]; void f(int i[]); int x; int v[x];') c = get_cursor(tu, 'c') i = get_cursor(tu, 'i') v = get_cursor(tu, 'v') diff --git a/cmake/caches/Apple-stage1.cmake b/cmake/caches/Apple-stage1.cmake new file mode 100644 index 00000000000..a5c3fdbbdfd --- /dev/null +++ b/cmake/caches/Apple-stage1.cmake @@ -0,0 +1,32 @@ +# This file sets up a CMakeCache for Apple-style bootstrap builds. It can be +# used on any Darwin system to approximate Apple Clang builds. + +if($ENV{DT_TOOLCHAIN_DIR}) + set(CMAKE_INSTALL_PREFIX $ENV{DT_TOOLCHAIN_DIR}/usr/) +else() + set(CMAKE_INSTALL_PREFIX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.toolchain/usr/) +endif() + +set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "") +set(CLANG_VENDOR Apple CACHE STRING "") +set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "") +set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "") +set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "") +set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "") +set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "") + +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(PACKAGE_VERSION 7.1.0 CACHE STRING "") + +# LIBCXX Settings +set(LIBCXX_INSTALL_LIBRARY OFF CACHE BOOL "") +set(LIBCXX_INSTALL_HEADERS ON CACHE BOOL "") +set(LIBCXX_OVERRIDE_DARWIN_INSTALL ON CACHE BOOL "") + +#bootstrap +set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "") +set(CLANG_BOOTSTRAP_CMAKE_ARGS + -C ${CMAKE_CURRENT_LIST_DIR}/Apple-stage2.cmake + CACHE STRING "") diff --git a/cmake/caches/Apple-stage2.cmake b/cmake/caches/Apple-stage2.cmake new file mode 100644 index 00000000000..bb319aaeb86 --- /dev/null +++ b/cmake/caches/Apple-stage2.cmake @@ -0,0 +1,30 @@ +# This file sets up a CMakeCache for Apple-style stage2 bootstrap. It is +# specified by the stage1 build. + +set(LLVM_TARGETS_TO_BUILD X86 ARM AArch64 CACHE STRING "") +set(CLANG_VENDOR Apple CACHE STRING "") +set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "") +set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "") +set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "") +set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "") +set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "") +set(CLANG_LINKS_TO_CREATE clang++ cc c++ CACHE STRING "") + +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -flto -gline-tables-only -DNDEBUG" CACHE STRING "") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -flto -gline-tables-only -DNDEBUG" CACHE STRING "") +set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") +set(PACKAGE_VERSION 7.1.0 CACHE STRING "") + +set(LIBCXX_INSTALL_LIBRARY OFF CACHE BOOL "") +set(LIBCXX_INSTALL_HEADERS OFF CACHE BOOL "") + +# setup toolchain +set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "") +set(LLVM_TOOLCHAIN_TOOLS + llvm-dsymutil + llvm-cov + llvm-dwarfdump + llvm-profdata + CACHE STRING "") diff --git a/cmake/caches/README.txt b/cmake/caches/README.txt new file mode 100644 index 00000000000..55e5e159db1 --- /dev/null +++ b/cmake/caches/README.txt @@ -0,0 +1,18 @@ +CMake Caches +============ + +This directory contains CMake cache scripts that pre-populate the CMakeCache in +a build directory with commonly used settings. + +The first two cache files in the directory are used by Apple to build the clang +distribution packaged with Xcode. You can use the caches with the following +CMake invocation: + +cmake -G + -C /tools/clang/cmake/caches/Apple-stage1.cmake + -DCMAKE_BUILD_TYPE=Release + [-DCMAKE_INSTALL_PREFIX=] + + +Building the `bootstrap` target from this generation will build clang, and +`bootstrap-install` will install it. diff --git a/docs/AddressSanitizer.rst b/docs/AddressSanitizer.rst index 66ed3447fdb..06e7da7a99f 100644 --- a/docs/AddressSanitizer.rst +++ b/docs/AddressSanitizer.rst @@ -196,12 +196,11 @@ Disabling Instrumentation with ``__attribute__((no_sanitize("address")))`` -------------------------------------------------------------------------- Some code should not be instrumented by AddressSanitizer. One may use the -function attribute ``__attribute__((no_sanitize("address")))`` -(which has deprecated synonyms -:ref:`no_sanitize_address ` and -`no_address_safety_analysis`) to disable instrumentation of a particular -function. This attribute may not be supported by other compilers, so we suggest -to use it together with ``__has_feature(address_sanitizer)``. +function attribute ``__attribute__((no_sanitize("address")))`` (which has +deprecated synonyms `no_sanitize_address` and `no_address_safety_analysis`) to +disable instrumentation of a particular function. This attribute may not be +supported by other compilers, so we suggest to use it together with +``__has_feature(address_sanitizer)``. Suppressing Errors in Recompiled Code (Blacklist) ------------------------------------------------- diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 47bb2e0c4b9..f42439a9bf1 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -47,6 +47,14 @@ if (LLVM_ENABLE_DOXYGEN) set(clang_doxygen_qhp_cust_filter_attrs "") endif() + option(LLVM_DOXYGEN_SVG + "Use svg instead of png files for doxygen graphs." OFF) + if (LLVM_DOXYGEN_SVG) + set(DOT_IMAGE_FORMAT "svg") + else() + set(DOT_IMAGE_FORMAT "png") + endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg @ONLY) @@ -64,6 +72,7 @@ if (LLVM_ENABLE_DOXYGEN) set(clang_doxygen_qhelpgenerator_path) set(clang_doxygen_qhp_cust_filter_name) set(clang_doxygen_qhp_cust_filter_attrs) + set(DOT_IMAGE_FORMAT) add_custom_target(doxygen-clang COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen.cfg diff --git a/docs/ClangFormat.rst b/docs/ClangFormat.rst index 45ea3271799..b4968ef1036 100644 --- a/docs/ClangFormat.rst +++ b/docs/ClangFormat.rst @@ -16,7 +16,7 @@ to format C/C++/Obj-C code. .. code-block:: console $ clang-format -help - OVERVIEW: A tool to format C/C++/Obj-C code. + OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code. If no arguments are specified, it formats the code from standard input and writes the result to the standard output. @@ -30,44 +30,53 @@ to format C/C++/Obj-C code. Clang-format options: - -cursor= - The position of the cursor when invoking - clang-format from an editor integration - -dump-config - Dump configuration options to stdout and exit. - Can be used with -style option. - -i - Inplace edit s, if specified. - -length= - Format a range of this length (in bytes). - Multiple ranges can be formatted by specifying - several -offset and -length pairs. - When only a single -offset is specified without - -length, clang-format will format up to the end - of the file. - Can only be used with one input file. - -lines= - : - format a range of - lines (both 1-based). - Multiple ranges can be formatted by specifying - several -lines arguments. - Can't be used with -offset and -length. - Can only be used with one input file. - -offset= - Format a range starting at this byte offset. - Multiple ranges can be formatted by specifying - several -offset and -length pairs. - Can only be used with one input file. - -output-replacements-xml - Output replacements as XML. - -style= - Coding style, currently supports: - LLVM, Google, Chromium, Mozilla, WebKit. - Use -style=file to load style configuration from - .clang-format file located in one of the parent - directories of the source file (or current - directory for stdin). - Use -style="{key: value, ...}" to set specific - parameters, e.g.: - -style="{BasedOnStyle: llvm, IndentWidth: 8}" - - General options: - - -help - Display available options (-help-hidden for more) - -help-list - Display list of available options (-help-list-hidden for more) - -version - Display the version of this program + -assume-filename= - When reading from stdin, clang-format assumes this + filename to look for a style config file (with + -style=file) and to determine the language. + -cursor= - The position of the cursor when invoking + clang-format from an editor integration + -dump-config - Dump configuration options to stdout and exit. + Can be used with -style option. + -fallback-style= - The name of the predefined style used as a + fallback in case clang-format is invoked with + -style=file, but can not find the .clang-format + file to use. + Use -fallback-style=none to skip formatting. + -i - Inplace edit s, if specified. + -length= - Format a range of this length (in bytes). + Multiple ranges can be formatted by specifying + several -offset and -length pairs. + When only a single -offset is specified without + -length, clang-format will format up to the end + of the file. + Can only be used with one input file. + -lines= - : - format a range of + lines (both 1-based). + Multiple ranges can be formatted by specifying + several -lines arguments. + Can't be used with -offset and -length. + Can only be used with one input file. + -offset= - Format a range starting at this byte offset. + Multiple ranges can be formatted by specifying + several -offset and -length pairs. + Can only be used with one input file. + -output-replacements-xml - Output replacements as XML. + -sort-includes - Sort touched include lines + -style= - Coding style, currently supports: + LLVM, Google, Chromium, Mozilla, WebKit. + Use -style=file to load style configuration from + .clang-format file located in one of the parent + directories of the source file (or current + directory for stdin). + Use -style="{key: value, ...}" to set specific + parameters, e.g.: + -style="{BasedOnStyle: llvm, IndentWidth: 8}" + + Generic Options: + + -help - Display available options (-help-hidden for more) + -help-list - Display list of available options (-help-list-hidden for more) + -version - Display the version of this program When the desired code formatting style is different from the available options, diff --git a/docs/ClangFormatStyleOptions.rst b/docs/ClangFormatStyleOptions.rst index 031daeeaa12..9b4ffe300fe 100644 --- a/docs/ClangFormatStyleOptions.rst +++ b/docs/ClangFormatStyleOptions.rst @@ -150,26 +150,61 @@ the configuration (without a prefix: ``Auto``). **AccessModifierOffset** (``int``) The extra indent or outdent of access modifiers, e.g. ``public:``. -**AlignAfterOpenBracket** (``bool``) +**AlignAfterOpenBracket** (``BracketAlignmentStyle``) If ``true``, horizontally aligns arguments after an open bracket. This applies to round brackets (parentheses), angle brackets and square brackets. This will result in formattings like - \code - someLongFunction(argument1, - argument2); - \endcode + + Possible values: + + * ``BAS_Align`` (in configuration: ``Align``) + Align parameters on the open bracket, e.g.: + + .. code-block:: c++ + + someLongFunction(argument1, + argument2); + * ``BAS_DontAlign`` (in configuration: ``DontAlign``) + Don't align, instead use ``ContinuationIndentWidth``, e.g.: + + .. code-block:: c++ + + someLongFunction(argument1, + argument2); + * ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``) + Always break after an open bracket, if the parameters don't fit + on a single line, e.g.: + + .. code-block:: c++ + + someLongFunction( + argument1, argument2); + **AlignConsecutiveAssignments** (``bool``) If ``true``, aligns consecutive assignments. This will align the assignment operators of consecutive lines. This will result in formattings like - \code - int aaaa = 12; - int b = 23; - int ccc = 23; - \endcode + + .. code-block:: c++ + + int aaaa = 12; + int b = 23; + int ccc = 23; + +**AlignConsecutiveDeclarations** (``bool``) + If ``true``, aligns consecutive declarations. + + This will align the declaration names of consecutive lines. This + will result in formattings like + + .. code-block:: c++ + + int aaaa = 12; + float b = 23; + std::string ccc = 23; **AlignEscapedNewlinesLeft** (``bool``) If ``true``, aligns escaped newlines as far left as possible. @@ -252,6 +287,30 @@ the configuration (without a prefix: ``Auto``). If ``false``, a function declaration's or function definition's parameters will either all be on the same line or will have one line each. +**BraceWrapping** (``BraceWrappingFlags``) + Control of individual brace wrapping cases. + + If ``BreakBeforeBraces`` is set to ``custom``, use this to specify how each + individual brace case should be handled. Otherwise, this is ignored. + + Nested configuration flags: + + * ``bool AfterClass`` Wrap class definitions. + * ``bool AfterControlStatement`` Wrap control statements (if/for/while/switch/..). + * ``bool AfterEnum`` Wrap enum definitions. + * ``bool AfterFunction`` Wrap function definitions. + * ``bool AfterNamespace`` Wrap namespace definitions. + * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (@autoreleasepool, interfaces, ..). + * ``bool AfterStruct`` Wrap struct definitions. + * ``bool AfterUnion`` Wrap union definitions. + * ``bool BeforeCatch`` Wrap before ``catch``. + * ``bool BeforeElse`` Wrap before ``else``. + * ``bool IndentBraces`` Indent the wrapped braces themselves. + + +**BreakAfterJavaFieldAnnotations** (``bool``) + Break after each annotation on a field in Java files. + **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) The way to wrap binary operators. @@ -279,13 +338,17 @@ the configuration (without a prefix: ``Auto``). Like ``Attach``, but break before braces on enum, function, and record definitions. * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) - Like ``Attach``, but break before function definitions, and 'else'. + Like ``Attach``, but break before function definitions, 'catch', and 'else'. * ``BS_Allman`` (in configuration: ``Allman``) Always break before braces. * ``BS_GNU`` (in configuration: ``GNU``) Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions. + * ``BS_WebKit`` (in configuration: ``WebKit``) + Like ``Attach``, but break before functions. + * ``BS_Custom`` (in configuration: ``Custom``) + Configure each individual brace in ``BraceWrapping``. **BreakBeforeTernaryOperators** (``bool``) @@ -356,13 +419,47 @@ the configuration (without a prefix: ``Auto``). instead of as function calls. These are expected to be macros of the form: - \code - FOREACH(, ...) - - \endcode + + .. code-block:: c++ + + FOREACH(, ...) + + + In the .clang-format configuration file, this can be configured like: + + .. code-block:: c++ + + ForEachMacros: ['RANGES_FOR', 'FOREACH'] For example: BOOST_FOREACH. +**IncludeCategories** (``std::vector``) + Regular expressions denoting the different #include categories used + for ordering #includes. + + These regular expressions are matched against the filename of an include + (including the <> or "") in order. The value belonging to the first + matching regular expression is assigned and #includes are sorted first + according to increasing category number and then alphabetically within + each category. + + If none of the regular expressions match, UINT_MAX is assigned as + category. The main header for a source file automatically gets category 0, + so that it is kept at the beginning of the #includes + (http://llvm.org/docs/CodingStandards.html#include-style). + + To configure this in the .clang-format file, use: + + .. code-block:: c++ + + IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.\*' + Priority: 1 + **IndentCaseLabels** (``bool``) Indent case labels one level from the switch statement. @@ -546,6 +643,26 @@ the configuration (without a prefix: ``Auto``). .. END_FORMAT_STYLE_OPTIONS +Adding additional style options +=============================== + +Each additional style option adds costs to the clang-format project. Some of +these costs affect the clang-format developement itself, as we need to make +sure that any given combination of options work and that new features don't +break any of the existing options in any way. There are also costs for end users +as options become less discoverable and people have to think about and make a +decision on options they don't really care about. + +The goal of the clang-format project is more on the side of supporting a +limited set of styles really well as opposed to supporting every single style +used by a codebase somewhere in the wild. Of course, we do want to support all +major projects and thus have established the following bar for adding style +options. Each new style option must .. + + * be used in a project of significant size (have dozens of contributors) + * have a publicly accessible style guide + * have a person willing to contribute and maintain patches + Examples ======== diff --git a/docs/CommandGuide/clang.rst b/docs/CommandGuide/clang.rst index 39dbe02a0b4..9f6d6f588e5 100644 --- a/docs/CommandGuide/clang.rst +++ b/docs/CommandGuide/clang.rst @@ -257,6 +257,13 @@ Code Generation Options Generate debug information. Note that Clang debug information works best at -O0. +.. option:: -gmodules + + Generate debug information that contains external references to + types defined in clang modules or precompiled headers instead of + emitting redundant debug type information into every object file. + This option implies `-fmodule-format=obj`. + .. option:: -fstandalone-debug -fno-standalone-debug Clang supports a number of optimizations to reduce the size of debug diff --git a/docs/ControlFlowIntegrity.rst b/docs/ControlFlowIntegrity.rst index b043d24a142..b583fc0debc 100644 --- a/docs/ControlFlowIntegrity.rst +++ b/docs/ControlFlowIntegrity.rst @@ -20,12 +20,14 @@ program's control flow. These schemes have been optimized for performance, allowing developers to enable them in release builds. To enable Clang's available CFI schemes, use the flag ``-fsanitize=cfi``. -As currently implemented, CFI relies on link-time optimization (LTO); so it is -required to specify ``-flto``, and the linker used must support LTO, for example -via the `gold plugin`_. To allow the checks to be implemented efficiently, -the program must be structured such that certain object files are compiled -with CFI enabled, and are statically linked into the program. This may -preclude the use of shared libraries in some cases. +As currently implemented, all of Clang's CFI schemes (``cfi-vcall``, +``cfi-derived-cast``, ``cfi-unrelated-cast``, ``cfi-nvcall``, ``cfi-icall``) +rely on link-time optimization (LTO); so it is required to specify +``-flto``, and the linker used must support LTO, for example via the `gold +plugin`_. To allow the checks to be implemented efficiently, the program must +be structured such that certain object files are compiled with CFI enabled, +and are statically linked into the program. This may preclude the use of +shared libraries in some cases. Clang currently implements forward-edge CFI for member function calls and bad cast checking. More schemes are under development. @@ -123,6 +125,54 @@ member functions on class instances with specific properties that works under most compilers and should not have security implications, so we allow it by default. It can be disabled with ``-fsanitize=cfi-cast-strict``. +Indirect Function Call Checking +------------------------------- + +This scheme checks that function calls take place using a function of the +correct dynamic type; that is, the dynamic type of the function must match +the static type used at the call. This CFI scheme can be enabled on its own +using ``-fsanitize=cfi-icall``. + +For this scheme to work, each indirect function call in the program, other +than calls in :ref:`blacklisted ` functions, must call a +function which was either compiled with ``-fsanitize=cfi-icall`` enabled, +or whose address was taken by a function in a translation unit compiled with +``-fsanitize=cfi-icall``. + +If a function in a translation unit compiled with ``-fsanitize=cfi-icall`` +takes the address of a function not compiled with ``-fsanitize=cfi-icall``, +that address may differ from the address taken by a function in a translation +unit not compiled with ``-fsanitize=cfi-icall``. This is technically a +violation of the C and C++ standards, but it should not affect most programs. + +Each translation unit compiled with ``-fsanitize=cfi-icall`` must be +statically linked into the program or shared library, and calls across +shared library boundaries are handled as if the callee was not compiled with +``-fsanitize=cfi-icall``. + +This scheme is currently only supported on the x86 and x86_64 architectures. + +``-fsanitize=cfi-icall`` and ``-fsanitize=function`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This tool is similar to ``-fsanitize=function`` in that both tools check +the types of function calls. However, the two tools occupy different points +on the design space; ``-fsanitize=function`` is a developer tool designed +to find bugs in local development builds, whereas ``-fsanitize=cfi-icall`` +is a security hardening mechanism designed to be deployed in release builds. + +``-fsanitize=function`` has a higher space and time overhead due to a more +complex type check at indirect call sites, as well as a need for run-time +type information (RTTI), which may make it unsuitable for deployment. Because +of the need for RTTI, ``-fsanitize=function`` can only be used with C++ +programs, whereas ``-fsanitize=cfi-icall`` can protect both C and C++ programs. + +On the other hand, ``-fsanitize=function`` conforms more closely with the C++ +standard and user expectations around interaction with shared libraries; +the identity of function pointers is maintained, and calls across shared +library boundaries are no different from calls within a single program or +shared library. + .. _cfi-blacklist: Blacklist diff --git a/docs/ControlFlowIntegrityDesign.rst b/docs/ControlFlowIntegrityDesign.rst index 89aa038d003..af3744576d7 100644 --- a/docs/ControlFlowIntegrityDesign.rst +++ b/docs/ControlFlowIntegrityDesign.rst @@ -273,3 +273,11 @@ Eliminating Bit Vector Checks for All-Ones Bit Vectors If the bit vector is all ones, the bit vector check is redundant; we simply need to check that the address is in range and well aligned. This is more likely to occur if the virtual tables are padded. + +Forward-Edge CFI for Indirect Function Calls +============================================ + +Sorry, no documentation yet, but see the comments at the top of +``LowerBitSets::buildBitSetsFromFunctions`` in `LowerBitSets.cpp`_. + +.. _LowerBitSets.cpp: http://llvm.org/klaus/llvm/blob/master/lib/Transforms/IPO/LowerBitSets.cpp diff --git a/docs/ExternalClangExamples.rst b/docs/ExternalClangExamples.rst index 71d50c23fa1..e6076a5be6d 100644 --- a/docs/ExternalClangExamples.rst +++ b/docs/ExternalClangExamples.rst @@ -20,7 +20,7 @@ where Clang is used are: If you know of (or wrote!) a tool or project using Clang, please send an email to Clang's `development discussion mailing list -`_ to have it added. +`_ to have it added. (or if you are already a Clang contributor, feel free to directly commit additions). Since the primary purpose of this page is to provide examples that can help developers, generally they must have code available. diff --git a/docs/InternalsManual.rst b/docs/InternalsManual.rst index 7f2a8fafccc..7959179d491 100644 --- a/docs/InternalsManual.rst +++ b/docs/InternalsManual.rst @@ -508,7 +508,7 @@ token. This concept maps directly to the "spelling location" for the token. ``SourceRange`` and ``CharSourceRange`` --------------------------------------- -.. mostly taken from http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-August/010595.html +.. mostly taken from http://lists.llvm.org/pipermail/cfe-dev/2010-August/010595.html Clang represents most source ranges by [first, last], where "first" and "last" each point to the beginning of their respective tokens. For example consider diff --git a/docs/LanguageExtensions.rst b/docs/LanguageExtensions.rst index 6a4dd5ccbf3..07b9c9968b2 100644 --- a/docs/LanguageExtensions.rst +++ b/docs/LanguageExtensions.rst @@ -415,7 +415,7 @@ dash indicates that an operation is not accepted according to a corresponding specification. ============================== ======= ======= ======= ======= - Opeator OpenCL AltiVec GCC NEON + Operator OpenCL AltiVec GCC NEON ============================== ======= ======= ======= ======= [] yes yes yes -- unary operators +, -- yes yes yes -- @@ -1540,6 +1540,33 @@ takes no arguments and produces a void result. Query for this feature with ``__has_builtin(__builtin_unreachable)``. +``__builtin_unpredictable`` +--------------------------- + +``__builtin_unpredictable`` is used to indicate that a branch condition is +unpredictable by hardware mechanisms such as branch prediction logic. + +**Syntax**: + +.. code-block:: c++ + + __builtin_unpredictable(long long) + +**Example of use**: + +.. code-block:: c++ + + if (__builtin_unpredictable(x > 0)) { + foo(); + } + +**Description**: + +The ``__builtin_unpredictable()`` builtin is expected to be used with control +flow conditions such as in ``if`` and ``switch`` statements. + +Query for this feature with ``__has_builtin(__builtin_unpredictable)``. + ``__sync_swap`` --------------- @@ -1652,17 +1679,20 @@ an example of their usage: errorcode_t security_critical_application(...) { unsigned x, y, result; ... - if (__builtin_umul_overflow(x, y, &result)) + if (__builtin_mul_overflow(x, y, &result)) return kErrorCodeHackers; ... use_multiply(result); ... } -A complete enumeration of the builtins are: +Clang provides the following checked arithmetic builtins: .. code-block:: c + bool __builtin_add_overflow (type1 x, type2 y, type3 *sum); + bool __builtin_sub_overflow (type1 x, type2 y, type3 *diff); + bool __builtin_mul_overflow (type1 x, type2 y, type3 *prod); bool __builtin_uadd_overflow (unsigned x, unsigned y, unsigned *sum); bool __builtin_uaddl_overflow (unsigned long x, unsigned long y, unsigned long *sum); bool __builtin_uaddll_overflow(unsigned long long x, unsigned long long y, unsigned long long *sum); @@ -1682,6 +1712,21 @@ A complete enumeration of the builtins are: bool __builtin_smull_overflow (long x, long y, long *prod); bool __builtin_smulll_overflow(long long x, long long y, long long *prod); +Each builtin performs the specified mathematical operation on the +first two arguments and stores the result in the third argument. If +possible, the result will be equal to mathematically-correct result +and the builtin will return 0. Otherwise, the builtin will return +1 and the result will be equal to the unique value that is equivalent +to the mathematically-correct result modulo two raised to the *k* +power, where *k* is the number of bits in the result type. The +behavior of these builtins is well-defined for all argument values. + +The first three builtins work generically for operands of any integer type, +including boolean types. The operands need not have the same type as each +other, or as the result. The other builtins may implicitly promote or +convert their operands before performing the operation. + +Query for this feature with ``__has_builtin(__builtin_add_overflow)``, etc. .. _langext-__c11_atomic: @@ -1715,6 +1760,9 @@ The macros ``__ATOMIC_RELAXED``, ``__ATOMIC_CONSUME``, ``__ATOMIC_ACQUIRE``, provided, with values corresponding to the enumerators of C11's ``memory_order`` enumeration. +(Note that Clang additionally provides GCC-compatible ``__atomic_*`` +builtins) + Low-level ARM exclusive memory builtins --------------------------------------- @@ -1730,6 +1778,7 @@ instructions for implementing atomic operations. void __builtin_arm_clrex(void); The types ``T`` currently supported are: + * Integer types with width at most 64 bits (or 128 bits on AArch64). * Floating-point types * Pointer types. @@ -1748,6 +1797,26 @@ care should be exercised. For these reasons the higher level atomic primitives should be preferred where possible. +Non-temporal load/store builtins +-------------------------------- + +Clang provides overloaded builtins allowing generation of non-temporal memory +accesses. + +.. code-block:: c + + T __builtin_nontemporal_load(T *addr); + void __builtin_nontemporal_store(T value, T *addr); + +The types ``T`` currently supported are: + +* Integer types. +* Floating-point types. +* Vector types. + +Note that the compiler does not guarantee that non-temporal loads or stores +will be used. + Non-standard C++11 Attributes ============================= @@ -1990,11 +2059,23 @@ iterations. Full unrolling is only possible if the loop trip count is known at compile time. Partial unrolling replicates the loop body within the loop and reduces the trip count. -If ``unroll(full)`` is specified the unroller will attempt to fully unroll the +If ``unroll(enable)`` is specified the unroller will attempt to fully unroll the loop if the trip count is known at compile time. If the fully unrolled code size is greater than an internal limit the loop will be partially unrolled up to this -limit. If the loop count is not known at compile time the loop will not be -unrolled. +limit. If the trip count is not known at compile time the loop will be partially +unrolled with a heuristically chosen unroll factor. + +.. code-block:: c++ + + #pragma clang loop unroll(enable) + for(...) { + ... + } + +If ``unroll(full)`` is specified the unroller will attempt to fully unroll the +loop if the trip count is known at compile time identically to +``unroll(enable)``. However, with ``unroll(full)`` the loop will not be unrolled +if the loop count is not known at compile time. .. code-block:: c++ @@ -2006,7 +2087,7 @@ unrolled. The unroll count can be specified explicitly with ``unroll_count(_value_)`` where _value_ is a positive integer. If this value is greater than the trip count the loop will be fully unrolled. Otherwise the loop is partially unrolled subject -to the same code size limit as with ``unroll(full)``. +to the same code size limit as with ``unroll(enable)``. .. code-block:: c++ diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index c977872f383..1f681e7f9a0 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -1,4236 +1,4754 @@ - - - -AST Matcher Reference - - - - - - - - - -
- -

AST Matcher Reference

- -

This document shows all currently implemented matchers. The matchers are grouped -by category and node type they match. You can click on matcher names to show the -matcher's source documentation.

- -

There are three different basic categories of matchers: -

-

- -

Within each category the matchers are ordered by node type they match on. -Note that if a matcher can match multiple node types, it will it will appear -multiple times. This means that by searching for Matcher<Stmt> you can -find all matchers that can be used to match on Stmt nodes.

- -

The exception to that rule are matchers that can match on any node. Those -are marked with a * and are listed in the beginning of each category.

- -

Note that the categorization of matchers is a great help when you combine -them into matcher expressions. You will usually want to form matcher expressions -that read like english sentences by alternating between node matchers and -narrowing or traversal matchers, like this: -

-recordDecl(hasDescendant(
-    ifStmt(hasTrueExpression(
-        expr(hasDescendant(
-            ifStmt()))))))
-
-

- - -

Node Matchers

- - -

Node matchers are at the core of matcher expressions - they specify the type -of node that is expected. Every match expression starts with a node matcher, -which can then be further refined with a narrowing or traversal matcher. All -traversal matchers take node matchers as their arguments.

- -

For convenience, all node matchers take an arbitrary number of arguments -and implicitly act as allOf matchers.

- -

Node matchers are the only matchers that support the bind("id") call to -bind the matched node to the given string, to be later retrieved from the -match callback.

- -

It is important to remember that the arguments to node matchers are -predicates on the same node, just with additional information about the type. -This is often useful to make matcher expression more readable by inlining bind -calls into redundant node matchers inside another node matcher: -

-// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on
-// the same node.
-recordDecl(decl().bind("id"), hasName("::MyClass"))
-
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Return typeNameParameters
Matcher<CXXCtorInitializer>ctorInitializerMatcher<CXXCtorInitializer>...
Matches constructor initializers.
-
-Examples matches i(42).
-  class C {
-    C() : i(42) {}
-    int i;
-  };
-
Matcher<Decl>accessSpecDeclMatcher<AccessSpecDecl>...
Matches C++ access specifier declarations.
-
-Given
-  class C {
-  public:
-    int a;
-  };
-accessSpecDecl()
-  matches 'public:'
-
Matcher<Decl>classTemplateDeclMatcher<ClassTemplateDecl>...
Matches C++ class template declarations.
-
-Example matches Z
-  template<class T> class Z {};
-
Matcher<Decl>classTemplateSpecializationDeclMatcher<ClassTemplateSpecializationDecl>...
Matches C++ class template specializations.
-
-Given
-  template<typename T> class A {};
-  template<> class A<double> {};
-  A<int> a;
-classTemplateSpecializationDecl()
-  matches the specializations A<int> and A<double>
-
Matcher<Decl>constructorDeclMatcher<CXXConstructorDecl>...
Matches C++ constructor declarations.
-
-Example matches Foo::Foo() and Foo::Foo(int)
-  class Foo {
-   public:
-    Foo();
-    Foo(int);
-    int DoSomething();
-  };
-
Matcher<Decl>declMatcher<Decl>...
Matches declarations.
-
-Examples matches X, C, and the friend declaration inside C;
-  void X();
-  class C {
-    friend X;
-  };
-
Matcher<Decl>declaratorDeclMatcher<DeclaratorDecl>...
Matches declarator declarations (field, variable, function
-and non-type template parameter declarations).
-
-Given
-  class X { int y; };
-declaratorDecl()
-  matches int y.
-
Matcher<Decl>destructorDeclMatcher<CXXDestructorDecl>...
Matches explicit C++ destructor declarations.
-
-Example matches Foo::~Foo()
-  class Foo {
-   public:
-    virtual ~Foo();
-  };
-
Matcher<Decl>enumConstantDeclMatcher<EnumConstantDecl>...
Matches enum constants.
-
-Example matches A, B, C
-  enum X {
-    A, B, C
-  };
-
Matcher<Decl>enumDeclMatcher<EnumDecl>...
Matches enum declarations.
-
-Example matches X
-  enum X {
-    A, B, C
-  };
-
Matcher<Decl>fieldDeclMatcher<FieldDecl>...
Matches field declarations.
-
-Given
-  class X { int m; };
-fieldDecl()
-  matches 'm'.
-
Matcher<Decl>friendDeclMatcher<FriendDecl>...
Matches friend declarations.
-
-Given
-  class X { friend void foo(); };
-friendDecl()
-  matches 'friend void foo()'.
-
Matcher<Decl>functionDeclMatcher<FunctionDecl>...
Matches function declarations.
-
-Example matches f
-  void f();
-
Matcher<Decl>functionTemplateDeclMatcher<FunctionTemplateDecl>...
Matches C++ function template declarations.
-
-Example matches f
-  template<class T> void f(T t) {}
-
Matcher<Decl>linkageSpecDeclMatcher<LinkageSpecDecl>...
Matches a declaration of a linkage specification.
-
-Given
-  extern "C" {}
-linkageSpecDecl()
-  matches "extern "C" {}"
-
Matcher<Decl>methodDeclMatcher<CXXMethodDecl>...
Matches method declarations.
-
-Example matches y
-  class X { void y(); };
-
Matcher<Decl>namedDeclMatcher<NamedDecl>...
Matches a declaration of anything that could have a name.
-
-Example matches X, S, the anonymous union type, i, and U;
-  typedef int X;
-  struct S {
-    union {
-      int i;
-    } U;
-  };
-
Matcher<Decl>namespaceDeclMatcher<NamespaceDecl>...
Matches a declaration of a namespace.
-
-Given
-  namespace {}
-  namespace test {}
-namespaceDecl()
-  matches "namespace {}" and "namespace test {}"
-
Matcher<Decl>parmVarDeclMatcher<ParmVarDecl>...
Matches parameter variable declarations.
-
-Given
-  void f(int x);
-parmVarDecl()
-  matches int x.
-
Matcher<Decl>recordDeclMatcher<CXXRecordDecl>...
Matches C++ class declarations.
-
-Example matches X, Z
-  class X;
-  template<class T> class Z {};
-
Matcher<Decl>translationUnitDeclMatcher<TranslationUnitDecl>...
Matches the top declaration context.
-
-Given
-  int X;
-  namespace NS {
-  int Y;
-  }  namespace NS
-decl(hasDeclContext(translationUnitDecl()))
-  matches "int X", but not "int Y".
-
Matcher<Decl>typedefDeclMatcher<TypedefDecl>...
Matches typedef declarations.
-
-Given
-  typedef int X;
-typedefDecl()
-  matches "typedef int X"
-
Matcher<Decl>unresolvedUsingValueDeclMatcher<UnresolvedUsingValueDecl>...
Matches unresolved using value declarations.
-
-Given
-  template<typename X>
-  class C : private X {
-    using X::x;
-  };
-unresolvedUsingValueDecl()
-  matches using X::x 
Matcher<Decl>usingDeclMatcher<UsingDecl>...
Matches using declarations.
-
-Given
-  namespace X { int x; }
-  using X::x;
-usingDecl()
-  matches using X::x 
Matcher<Decl>usingDirectiveDeclMatcher<UsingDirectiveDecl>...
Matches using namespace declarations.
-
-Given
-  namespace X { int x; }
-  using namespace X;
-usingDirectiveDecl()
-  matches using namespace X 
Matcher<Decl>valueDeclMatcher<ValueDecl>...
Matches any value declaration.
-
-Example matches A, B, C and F
-  enum X { A, B, C };
-  void F();
-
Matcher<Decl>varDeclMatcher<VarDecl>...
Matches variable declarations.
-
-Note: this does not match declarations of member variables, which are
-"field" declarations in Clang parlance.
-
-Example matches a
-  int a;
-
Matcher<NestedNameSpecifierLoc>nestedNameSpecifierLocMatcher<NestedNameSpecifierLoc>...
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
-
Matcher<NestedNameSpecifier>nestedNameSpecifierMatcher<NestedNameSpecifier>...
Matches nested name specifiers.
-
-Given
-  namespace ns {
-    struct A { static void f(); };
-    void A::f() {}
-    void g() { A::f(); }
-  }
-  ns::A a;
-nestedNameSpecifier()
-  matches "ns::" and both "A::"
-
Matcher<QualType>qualTypeMatcher<QualType>...
Matches QualTypes in the clang AST.
-
Matcher<Stmt>CUDAKernelCallExprMatcher<CUDAKernelCallExpr>...
Matches CUDA kernel call expression.
-
-Example matches,
-  kernel<<<i,j>>>();
-
Matcher<Stmt>arraySubscriptExprMatcher<ArraySubscriptExpr>...
Matches array subscript expressions.
-
-Given
-  int i = a[1];
-arraySubscriptExpr()
-  matches "a[1]"
-
Matcher<Stmt>asmStmtMatcher<AsmStmt>...
Matches asm statements.
-
- int i = 100;
-  __asm("mov al, 2");
-asmStmt()
-  matches '__asm("mov al, 2")'
-
Matcher<Stmt>binaryOperatorMatcher<BinaryOperator>...
Matches binary operator expressions.
-
-Example matches a || b
-  !(a || b)
-
Matcher<Stmt>bindTemporaryExprMatcher<CXXBindTemporaryExpr>...
Matches nodes where temporaries are created.
-
-Example matches FunctionTakesString(GetStringByValue())
-    (matcher = bindTemporaryExpr())
-  FunctionTakesString(GetStringByValue());
-  FunctionTakesStringByPointer(GetStringPointer());
-
Matcher<Stmt>boolLiteralMatcher<CXXBoolLiteralExpr>...
Matches bool literals.
-
-Example matches true
-  true
-
Matcher<Stmt>breakStmtMatcher<BreakStmt>...
Matches break statements.
-
-Given
-  while (true) { break; }
-breakStmt()
-  matches 'break'
-
Matcher<Stmt>cStyleCastExprMatcher<CStyleCastExpr>...
Matches a C-style cast expression.
-
-Example: Matches (int*) 2.2f in
-  int i = (int) 2.2f;
-
Matcher<Stmt>callExprMatcher<CallExpr>...
Matches call expressions.
-
-Example matches x.y() and y()
-  X x;
-  x.y();
-  y();
-
Matcher<Stmt>caseStmtMatcher<CaseStmt>...
Matches case statements inside switch statements.
-
-Given
-  switch(a) { case 42: break; default: break; }
-caseStmt()
-  matches 'case 42: break;'.
-
Matcher<Stmt>castExprMatcher<CastExpr>...
Matches any cast nodes of Clang's AST.
-
-Example: castExpr() matches each of the following:
-  (int) 3;
-  const_cast<Expr *>(SubExpr);
-  char c = 0;
-but does not match
-  int i = (0);
-  int k = 0;
-
Matcher<Stmt>catchStmtMatcher<CXXCatchStmt>...
Matches catch statements.
-
-  try {} catch(int i) {}
-catchStmt()
-  matches 'catch(int i)'
-
Matcher<Stmt>characterLiteralMatcher<CharacterLiteral>...
Matches character literals (also matches wchar_t).
-
-Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
-though.
-
-Example matches 'a', L'a'
-  char ch = 'a'; wchar_t chw = L'a';
-
Matcher<Stmt>compoundLiteralExprMatcher<CompoundLiteralExpr>...
Matches compound (i.e. non-scalar) literals
-
-Example match: {1}, (1, 2)
-  int array[4] = {1}; vector int myvec = (vector int)(1, 2);
-
Matcher<Stmt>compoundStmtMatcher<CompoundStmt>...
Matches compound statements.
-
-Example matches '{}' and '{{}}'in 'for (;;) {{}}'
-  for (;;) {{}}
-
Matcher<Stmt>conditionalOperatorMatcher<ConditionalOperator>...
Matches conditional operator expressions.
-
-Example matches a ? b : c
-  (a ? b : c) + 42
-
Matcher<Stmt>constCastExprMatcher<CXXConstCastExpr>...
Matches a const_cast expression.
-
-Example: Matches const_cast<int*>(&r) in
-  int n = 42;
-  const int &r(n);
-  int* p = const_cast<int*>(&r);
-
Matcher<Stmt>constructExprMatcher<CXXConstructExpr>...
Matches constructor call expressions (including implicit ones).
-
-Example matches string(ptr, n) and ptr within arguments of f
-    (matcher = constructExpr())
-  void f(const string &a, const string &b);
-  char *ptr;
-  int n;
-  f(string(ptr, n), ptr);
-
Matcher<Stmt>continueStmtMatcher<ContinueStmt>...
Matches continue statements.
-
-Given
-  while (true) { continue; }
-continueStmt()
-  matches 'continue'
-
Matcher<Stmt>declRefExprMatcher<DeclRefExpr>...
Matches expressions that refer to declarations.
-
-Example matches x in if (x)
-  bool x;
-  if (x) {}
-
Matcher<Stmt>declStmtMatcher<DeclStmt>...
Matches declaration statements.
-
-Given
-  int a;
-declStmt()
-  matches 'int a'.
-
Matcher<Stmt>defaultArgExprMatcher<CXXDefaultArgExpr>...
Matches the value of a default argument at the call site.
-
-Example matches the CXXDefaultArgExpr placeholder inserted for the
-    default value of the second parameter in the call expression f(42)
-    (matcher = defaultArgExpr())
-  void f(int x, int y = 0);
-  f(42);
-
Matcher<Stmt>defaultStmtMatcher<DefaultStmt>...
Matches default statements inside switch statements.
-
-Given
-  switch(a) { case 42: break; default: break; }
-defaultStmt()
-  matches 'default: break;'.
-
Matcher<Stmt>deleteExprMatcher<CXXDeleteExpr>...
Matches delete expressions.
-
-Given
-  delete X;
-deleteExpr()
-  matches 'delete X'.
-
Matcher<Stmt>doStmtMatcher<DoStmt>...
Matches do statements.
-
-Given
-  do {} while (true);
-doStmt()
-  matches 'do {} while(true)'
-
Matcher<Stmt>dynamicCastExprMatcher<CXXDynamicCastExpr>...
Matches a dynamic_cast expression.
-
-Example:
-  dynamicCastExpr()
-matches
-  dynamic_cast<D*>(&b);
-in
-  struct B { virtual ~B() {} }; struct D : B {};
-  B b;
-  D* p = dynamic_cast<D*>(&b);
-
Matcher<Stmt>explicitCastExprMatcher<ExplicitCastExpr>...
Matches explicit cast expressions.
-
-Matches any cast expression written in user code, whether it be a
-C-style cast, a functional-style cast, or a keyword cast.
-
-Does not match implicit conversions.
-
-Note: the name "explicitCast" is chosen to match Clang's terminology, as
-Clang uses the term "cast" to apply to implicit conversions as well as to
-actual cast expressions.
-
-hasDestinationType.
-
-Example: matches all five of the casts in
-  int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))
-but does not match the implicit conversion in
-  long ell = 42;
-
Matcher<Stmt>exprMatcher<Expr>...
Matches expressions.
-
-Example matches x()
-  void f() { x(); }
-
Matcher<Stmt>exprWithCleanupsMatcher<ExprWithCleanups>...
Matches expressions that introduce cleanups to be run at the end
-of the sub-expression's evaluation.
-
-Example matches std::string()
-  const std::string str = std::string();
-
Matcher<Stmt>floatLiteralMatcher<FloatingLiteral>...
Matches float literals of all sizes encodings, e.g.
-1.0, 1.0f, 1.0L and 1e10.
-
-Does not match implicit conversions such as
-  float a = 10;
-
Matcher<Stmt>forRangeStmtMatcher<CXXForRangeStmt>...
Matches range-based for statements.
-
-forRangeStmt() matches 'for (auto a : i)'
-  int i[] =  {1, 2, 3}; for (auto a : i);
-  for(int j = 0; j < 5; ++j);
-
Matcher<Stmt>forStmtMatcher<ForStmt>...
Matches for statements.
-
-Example matches 'for (;;) {}'
-  for (;;) {}
-  int i[] =  {1, 2, 3}; for (auto a : i);
-
Matcher<Stmt>functionalCastExprMatcher<CXXFunctionalCastExpr>...
Matches functional cast expressions
-
-Example: Matches Foo(bar);
-  Foo f = bar;
-  Foo g = (Foo) bar;
-  Foo h = Foo(bar);
-
Matcher<Stmt>gotoStmtMatcher<GotoStmt>...
Matches goto statements.
-
-Given
-  goto FOO;
-  FOO: bar();
-gotoStmt()
-  matches 'goto FOO'
-
Matcher<Stmt>ifStmtMatcher<IfStmt>...
Matches if statements.
-
-Example matches 'if (x) {}'
-  if (x) {}
-
Matcher<Stmt>implicitCastExprMatcher<ImplicitCastExpr>...
Matches the implicit cast nodes of Clang's AST.
-
-This matches many different places, including function call return value
-eliding, as well as any type conversions.
-
Matcher<Stmt>initListExprMatcher<InitListExpr>...
Matches init list expressions.
-
-Given
-  int a[] = { 1, 2 };
-  struct B { int x, y; };
-  B b = { 5, 6 };
-initListExpr()
-  matches "{ 1, 2 }" and "{ 5, 6 }"
-
Matcher<Stmt>integerLiteralMatcher<IntegerLiteral>...
Matches integer literals of all sizes encodings, e.g.
-1, 1L, 0x1 and 1U.
-
-Does not match character-encoded integers such as L'a'.
-
Matcher<Stmt>labelStmtMatcher<LabelStmt>...
Matches label statements.
-
-Given
-  goto FOO;
-  FOO: bar();
-labelStmt()
-  matches 'FOO:'
-
Matcher<Stmt>lambdaExprMatcher<LambdaExpr>...
Matches lambda expressions.
-
-Example matches [&](){return 5;}
-  [&](){return 5;}
-
Matcher<Stmt>materializeTemporaryExprMatcher<MaterializeTemporaryExpr>...
Matches nodes where temporaries are materialized.
-
-Example: Given
-  struct T {void func()};
-  T f();
-  void g(T);
-materializeTemporaryExpr() matches 'f()' in these statements
-  T u(f());
-  g(f());
-but does not match
-  f();
-  f().func();
-
Matcher<Stmt>memberCallExprMatcher<CXXMemberCallExpr>...
Matches member call expressions.
-
-Example matches x.y()
-  X x;
-  x.y();
-
Matcher<Stmt>memberExprMatcher<MemberExpr>...
Matches member expressions.
-
-Given
-  class Y {
-    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
-    int a; static int b;
-  };
-memberExpr()
-  matches this->x, x, y.x, a, this->b
-
Matcher<Stmt>newExprMatcher<CXXNewExpr>...
Matches new expressions.
-
-Given
-  new X;
-newExpr()
-  matches 'new X'.
-
Matcher<Stmt>nullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>...
Matches nullptr literal.
-
Matcher<Stmt>nullStmtMatcher<NullStmt>...
Matches null statements.
-
-  foo();;
-nullStmt()
-  matches the second ';'
-
Matcher<Stmt>operatorCallExprMatcher<CXXOperatorCallExpr>...
Matches overloaded operator calls.
-
-Note that if an operator isn't overloaded, it won't match. Instead, use
-binaryOperator matcher.
-Currently it does not match operators such as new delete.
-FIXME: figure out why these do not match?
-
-Example matches both operator<<((o << b), c) and operator<<(o, b)
-    (matcher = operatorCallExpr())
-  ostream &operator<< (ostream &out, int i) { };
-  ostream &o; int b = 1, c = 1;
-  o << b << c;
-
Matcher<Stmt>reinterpretCastExprMatcher<CXXReinterpretCastExpr>...
Matches a reinterpret_cast expression.
-
-Either the source expression or the destination type can be matched
-using has(), but hasDestinationType() is more specific and can be
-more readable.
-
-Example matches reinterpret_cast<char*>(&p) in
-  void* p = reinterpret_cast<char*>(&p);
-
Matcher<Stmt>returnStmtMatcher<ReturnStmt>...
Matches return statements.
-
-Given
-  return 1;
-returnStmt()
-  matches 'return 1'
-
Matcher<Stmt>staticCastExprMatcher<CXXStaticCastExpr>...
Matches a C++ static_cast expression.
-
-hasDestinationType
-reinterpretCast
-
-Example:
-  staticCastExpr()
-matches
-  static_cast<long>(8)
-in
-  long eight(static_cast<long>(8));
-
Matcher<Stmt>stmtMatcher<Stmt>...
Matches statements.
-
-Given
-  { ++a; }
-stmt()
-  matches both the compound statement '{ ++a; }' and '++a'.
-
Matcher<Stmt>stringLiteralMatcher<StringLiteral>...
Matches string literals (also matches wide string literals).
-
-Example matches "abcd", L"abcd"
-  char *s = "abcd"; wchar_t *ws = L"abcd"
-
Matcher<Stmt>substNonTypeTemplateParmExprMatcher<SubstNonTypeTemplateParmExpr>...
Matches substitutions of non-type template parameters.
-
-Given
-  template <int N>
-  struct A { static const int n = N; };
-  struct B : public A<42> {};
-substNonTypeTemplateParmExpr()
-  matches "N" in the right-hand side of "static const int n = N;"
-
Matcher<Stmt>switchCaseMatcher<SwitchCase>...
Matches case and default statements inside switch statements.
-
-Given
-  switch(a) { case 42: break; default: break; }
-switchCase()
-  matches 'case 42: break;' and 'default: break;'.
-
Matcher<Stmt>switchStmtMatcher<SwitchStmt>...
Matches switch statements.
-
-Given
-  switch(a) { case 42: break; default: break; }
-switchStmt()
-  matches 'switch(a)'.
-
Matcher<Stmt>temporaryObjectExprMatcher<CXXTemporaryObjectExpr>...
Matches functional cast expressions having N != 1 arguments
-
-Example: Matches Foo(bar, bar)
-  Foo h = Foo(bar, bar);
-
Matcher<Stmt>thisExprMatcher<CXXThisExpr>...
Matches implicit and explicit this expressions.
-
-Example matches the implicit this expression in "return i".
-    (matcher = thisExpr())
-struct foo {
-  int i;
-  int f() { return i; }
-};
-
Matcher<Stmt>throwExprMatcher<CXXThrowExpr>...
Matches throw expressions.
-
-  try { throw 5; } catch(int i) {}
-throwExpr()
-  matches 'throw 5'
-
Matcher<Stmt>tryStmtMatcher<CXXTryStmt>...
Matches try statements.
-
-  try {} catch(int i) {}
-tryStmt()
-  matches 'try {}'
-
Matcher<Stmt>unaryExprOrTypeTraitExprMatcher<UnaryExprOrTypeTraitExpr>...
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
-
-Given
-  Foo x = bar;
-  int y = sizeof(x) + alignof(x);
-unaryExprOrTypeTraitExpr()
-  matches sizeof(x) and alignof(x)
-
Matcher<Stmt>unaryOperatorMatcher<UnaryOperator>...
Matches unary operator expressions.
-
-Example matches !a
-  !a || b
-
Matcher<Stmt>unresolvedConstructExprMatcher<CXXUnresolvedConstructExpr>...
Matches unresolved constructor call expressions.
-
-Example matches T(t) in return statement of f
-    (matcher = unresolvedConstructExpr())
-  template <typename T>
-  void f(const T& t) { return T(t); }
-
Matcher<Stmt>userDefinedLiteralMatcher<UserDefinedLiteral>...
Matches user defined literal operator call.
-
-Example match: "foo"_suffix
-
Matcher<Stmt>whileStmtMatcher<WhileStmt>...
Matches while statements.
-
-Given
-  while (true) {}
-whileStmt()
-  matches 'while (true) {}'.
-
Matcher<TemplateArgument>templateArgumentMatcher<TemplateArgument>...
Matches template arguments.
-
-Given
-  template <typename T> struct C {};
-  C<int> c;
-templateArgument()
-  matches 'int' in C<int>.
-
Matcher<TypeLoc>typeLocMatcher<TypeLoc>...
Matches TypeLocs in the clang AST.
-
Matcher<Type>arrayTypeMatcher<ArrayType>...
Matches all kinds of arrays.
-
-Given
-  int a[] = { 2, 3 };
-  int b[4];
-  void f() { int c[a[0]]; }
-arrayType()
-  matches "int a[]", "int b[4]" and "int c[a[0]]";
-
Matcher<Type>atomicTypeMatcher<AtomicType>...
Matches atomic types.
-
-Given
-  _Atomic(int) i;
-atomicType()
-  matches "_Atomic(int) i"
-
Matcher<Type>autoTypeMatcher<AutoType>...
Matches types nodes representing C++11 auto types.
-
-Given:
-  auto n = 4;
-  int v[] = { 2, 3 }
-  for (auto i : v) { }
-autoType()
-  matches "auto n" and "auto i"
-
Matcher<Type>blockPointerTypeMatcher<BlockPointerType>...
Matches block pointer types, i.e. types syntactically represented as
-"void (^)(int)".
-
-The pointee is always required to be a FunctionType.
-
Matcher<Type>builtinTypeMatcher<BuiltinType>...
Matches builtin Types.
-
-Given
-  struct A {};
-  A a;
-  int b;
-  float c;
-  bool d;
-builtinType()
-  matches "int b", "float c" and "bool d"
-
Matcher<Type>complexTypeMatcher<ComplexType>...
Matches C99 complex types.
-
-Given
-  _Complex float f;
-complexType()
-  matches "_Complex float f"
-
Matcher<Type>constantArrayTypeMatcher<ConstantArrayType>...
Matches C arrays with a specified constant size.
-
-Given
-  void() {
-    int a[2];
-    int b[] = { 2, 3 };
-    int c[b[0]];
-  }
-constantArrayType()
-  matches "int a[2]"
-
Matcher<Type>dependentSizedArrayTypeMatcher<DependentSizedArrayType>...
Matches C++ arrays whose size is a value-dependent expression.
-
-Given
-  template<typename T, int Size>
-  class array {
-    T data[Size];
-  };
-dependentSizedArrayType
-  matches "T data[Size]"
-
Matcher<Type>elaboratedTypeMatcher<ElaboratedType>...
Matches types specified with an elaborated type keyword or with a
-qualified name.
-
-Given
-  namespace N {
-    namespace M {
-      class D {};
-    }
-  }
-  class C {};
-
-  class C c;
-  N::M::D d;
-
-elaboratedType() matches the type of the variable declarations of both
-c and d.
-
Matcher<Type>functionTypeMatcher<FunctionType>...
Matches FunctionType nodes.
-
-Given
-  int (*f)(int);
-  void g();
-functionType()
-  matches "int (*f)(int)" and the type of "g".
-
Matcher<Type>incompleteArrayTypeMatcher<IncompleteArrayType>...
Matches C arrays with unspecified size.
-
-Given
-  int a[] = { 2, 3 };
-  int b[42];
-  void f(int c[]) { int d[a[0]]; };
-incompleteArrayType()
-  matches "int a[]" and "int c[]"
-
Matcher<Type>lValueReferenceTypeMatcher<LValueReferenceType>...
Matches lvalue reference types.
-
-Given:
-  int *a;
-  int &b = *a;
-  int &&c = 1;
-  auto &d = b;
-  auto &&e = c;
-  auto &&f = 2;
-  int g = 5;
-
-lValueReferenceType() matches the types of b, d, and e. e is
-matched since the type is deduced as int& by reference collapsing rules.
-
Matcher<Type>memberPointerTypeMatcher<MemberPointerType>...
Matches member pointer types.
-Given
-  struct A { int i; }
-  A::* ptr = A::i;
-memberPointerType()
-  matches "A::* ptr"
-
Matcher<Type>parenTypeMatcher<ParenType>...
Matches ParenType nodes.
-
-Given
-  int (*ptr_to_array)[4];
-  int *array_of_ptrs[4];
-
-varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not
-array_of_ptrs.
-
Matcher<Type>pointerTypeMatcher<PointerType>...
Matches pointer types.
-
-Given
-  int *a;
-  int &b = *a;
-  int c = 5;
-pointerType()
-  matches "int *a"
-
Matcher<Type>rValueReferenceTypeMatcher<RValueReferenceType>...
Matches rvalue reference types.
-
-Given:
-  int *a;
-  int &b = *a;
-  int &&c = 1;
-  auto &d = b;
-  auto &&e = c;
-  auto &&f = 2;
-  int g = 5;
-
-rValueReferenceType() matches the types of c and f. e is not
-matched as it is deduced to int& by reference collapsing rules.
-
Matcher<Type>recordTypeMatcher<RecordType>...
Matches record types (e.g. structs, classes).
-
-Given
-  class C {};
-  struct S {};
-
-  C c;
-  S s;
-
-recordType() matches the type of the variable declarations of both c
-and s.
-
Matcher<Type>referenceTypeMatcher<ReferenceType>...
Matches both lvalue and rvalue reference types.
-
-Given
-  int *a;
-  int &b = *a;
-  int &&c = 1;
-  auto &d = b;
-  auto &&e = c;
-  auto &&f = 2;
-  int g = 5;
-
-referenceType() matches the types of b, c, d, e, and f.
-
Matcher<Type>templateSpecializationTypeMatcher<TemplateSpecializationType>...
Matches template specialization types.
-
-Given
-  template <typename T>
-  class C { };
-
-  template class C<int>;  A
-  C<char> var;            B
-
-templateSpecializationType() matches the type of the explicit
-instantiation in A and the type of the variable declaration in B.
-
Matcher<Type>typeMatcher<Type>...
Matches Types in the clang AST.
-
Matcher<Type>typedefTypeMatcher<TypedefType>...
Matches typedef types.
-
-Given
-  typedef int X;
-typedefType()
-  matches "typedef int X"
-
Matcher<Type>unaryTransformTypeMatcher<UnaryTransformType>...
Matches types nodes representing unary type transformations.
-
-Given:
-  typedef __underlying_type(T) type;
-unaryTransformType()
-  matches "__underlying_type(T)"
-
Matcher<Type>variableArrayTypeMatcher<VariableArrayType>...
Matches C arrays with a specified size that is not an
-integer-constant-expression.
-
-Given
-  void f() {
-    int a[] = { 2, 3 }
-    int b[42];
-    int c[a[0]];
-  }
-variableArrayType()
-  matches "int c[a[0]]"
-
- - -

Narrowing Matchers

- - -

Narrowing matchers match certain attributes on the current node, thus -narrowing down the set of nodes of the current type to match on.

- -

There are special logical narrowing matchers (allOf, anyOf, anything and unless) -which allow users to create more powerful match expressions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Return typeNameParameters
Matcher<*>allOfMatcher<*>, ..., Matcher<*>
Matches if all given matchers match.
-
-Usable as: Any Matcher
-
Matcher<*>anyOfMatcher<*>, ..., Matcher<*>
Matches if any of the given matchers matches.
-
-Usable as: Any Matcher
-
Matcher<*>anything
Matches any node.
-
-Useful when another matcher requires a child matcher, but there's no
-additional constraint. This will often be used with an explicit conversion
-to an internal::Matcher<> type such as TypeMatcher.
-
-Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
-"int* p" and "void f()" in
-  int* p;
-  void f();
-
-Usable as: Any Matcher
-
Matcher<*>unlessMatcher<*>
Matches if the provided matcher does not match.
-
-Example matches Y (matcher = recordDecl(unless(hasName("X"))))
-  class X {};
-  class Y {};
-
-Usable as: Any Matcher
-
Matcher<BinaryOperator>hasOperatorNamestd::string Name
Matches the operator Name of operator expressions (binary or
-unary).
-
-Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
-  !(a || b)
-
Matcher<CXXBoolLiteral>equalsValueT Value
Matches literals that are equal to the given value.
-
-Example matches true (matcher = boolLiteral(equals(true)))
-  true
-
-Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
-           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
-
Matcher<CXXCatchStmt>isCatchAll
Matches a C++ catch statement that has a handler that catches any exception type.
-
-Example matches catch(...) (matcher = catchStmt(isCatchAll()))
-  try {
-    // ...
-  } catch(...) {
-  }
-
Matcher<CXXConstructExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
-a specific number of arguments (including absent default arguments).
-
-Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
-  void f(int x, int y);
-  f(0, 0);
-
Matcher<CXXConstructExpr>isListInitialization
Matches a constructor call expression which uses list initialization.
-
Matcher<CXXCtorInitializer>isWritten
Matches a constructor initializer if it is explicitly written in
-code (as opposed to implicitly added by the compiler).
-
-Given
-  struct Foo {
-    Foo() { }
-    Foo(int) : foo_("A") { }
-    string foo_;
-  };
-constructorDecl(hasAnyConstructorInitializer(isWritten()))
-  will match Foo(int), but not Foo()
-
Matcher<CXXMethodDecl>isConst
Matches if the given method declaration is const.
-
-Given
-struct A {
-  void foo() const;
-  void bar();
-};
-
-methodDecl(isConst()) matches A::foo() but not A::bar()
-
Matcher<CXXMethodDecl>isFinal
Matches if the given method declaration is final.
-
-Given:
-
-struct A {
-  virtual void foo();
-  virtual void bar();
-};
-
-struct B : A {
-  void foo() final;
-  void bar();
-};
-
-methodDecl(isFinal()) matches B::foo() but not B::bar(), A::foo(), or A::bar()
-
Matcher<CXXMethodDecl>isOverride
Matches if the given method declaration overrides another method.
-
-Given
-  class A {
-   public:
-    virtual void x();
-  };
-  class B : public A {
-   public:
-    virtual void x();
-  };
-  matches B::x
-
Matcher<CXXMethodDecl>isPure
Matches if the given method declaration is pure.
-
-Given
-  class A {
-   public:
-    virtual void x() = 0;
-  };
-  matches A::x
-
Matcher<CXXMethodDecl>isVirtual
Matches if the given method declaration is virtual.
-
-Given
-  class A {
-   public:
-    virtual void x();
-  };
-  matches A::x
-
Matcher<CXXOperatorCallExpr>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.
-
-Matches overloaded operator names specified in strings without the
-"operator" prefix: e.g. "<<".
-
-Given:
-  class A { int operator*(); };
-  const A &operator<<(const A &a, const A &b);
-  A a;
-  a << a;   <-- This matches
-
-operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified
-line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches
-the declaration of A.
-
-Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
-
Matcher<CXXRecordDecl>isDerivedFromstd::string BaseName
Overloaded method as shortcut for isDerivedFrom(hasName(...)).
-
Matcher<CXXRecordDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
-static member variable template instantiations.
-
-Given
-  template<typename T> void A(T t) { }
-  template<> void A(int N) { }
-functionDecl(isExplicitTemplateSpecialization())
-  matches the specialization A<int>().
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<CXXRecordDecl>isSameOrDerivedFromstd::string BaseName
Overloaded method as shortcut for
-isSameOrDerivedFrom(hasName(...)).
-
Matcher<CXXRecordDecl>isFinal
Matches if the given class declaration is final.
-
-Given:
-
-struct A {};
-
-struct B final : A {};
-
-recordDecl(isFinal()) matches B but not A.
-
Matcher<CXXRecordDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
-member variable template instantiations.
-
-Given
-  template <typename T> class X {}; class A {}; X<A> x;
-or
-  template <typename T> class X {}; class A {}; template class X<A>;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  matches the template instantiation of X<A>.
-
-But given
-  template <typename T>  class X {}; class A {};
-  template <> class X<A> {}; X<A> x;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  does not match, as X<A> is an explicit template specialization.
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<CallExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
-a specific number of arguments (including absent default arguments).
-
-Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
-  void f(int x, int y);
-  f(0, 0);
-
Matcher<CharacterLiteral>equalsValueT Value
Matches literals that are equal to the given value.
-
-Example matches true (matcher = boolLiteral(equals(true)))
-  true
-
-Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
-           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
-
Matcher<ClassTemplateSpecializationDecl>templateArgumentCountIsunsigned N
Matches if the number of template arguments equals N.
-
-Given
-  template<typename T> struct C {};
-  C<int> c;
-classTemplateSpecializationDecl(templateArgumentCountIs(1))
-  matches C<int>.
-
Matcher<CompoundStmt>statementCountIsunsigned N
Checks that a compound statement contains a specific number of
-child statements.
-
-Example: Given
-  { for (;;) {} }
-compoundStmt(statementCountIs(0)))
-  matches '{}'
-  but does not match the outer compound statement.
-
Matcher<ConstantArrayType>hasSizeunsigned N
Matches ConstantArrayType nodes that have the specified size.
-
-Given
-  int a[42];
-  int b[2 * 21];
-  int c[41], d[43];
-constantArrayType(hasSize(42))
-  matches "int a[42]" and "int b[2 * 21]"
-
Matcher<DeclStmt>declCountIsunsigned N
Matches declaration statements that contain a specific number of
-declarations.
-
-Example: Given
-  int a, b;
-  int c;
-  int d = 2, e;
-declCountIs(2)
-  matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
-
Matcher<Decl>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
-
-Matches a node if it equals the node previously bound to ID.
-
-Given
-  class X { int a; int b; };
-recordDecl(
-    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
-    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
-  matches the class X, as a and b have the same type.
-
-Note that when multiple matches are involved via forEach* matchers,
-equalsBoundNodes acts as a filter.
-For example:
-compoundStmt(
-    forEachDescendant(varDecl().bind("d")),
-    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
-will trigger a match for each combination of variable declaration
-and reference to that variable declaration within a compound statement.
-
Matcher<Decl>hasAttrattr::Kind AttrKind
Matches declaration that has a given attribute.
-
-Given
-  __attribute__((device)) void f() { ... }
-decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of
-f. If the matcher is use from clang-query, attr::Kind parameter should be
-passed as a quoted string. e.g., hasAttr("attr::CUDADevice").
-
Matcher<Decl>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
-partially matching a given regex.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
-  #include "ASTMatcher.h"
-  class X {};
-ASTMatcher.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Decl>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
-
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
-  #include <Y.h>
-  class X {};
-Y.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Decl>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
-  #include <SystemHeader.h>
-  class X {};
-SystemHeader.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Decl>isImplicit
Matches a declaration that has been implicitly added
-by the compiler (eg. implicit defaultcopy constructors).
-
Matcher<Decl>isPrivate
Matches private C++ declarations.
-
-Given
-  class C {
-  public:    int a;
-  protected: int b;
-  private:   int c;
-  };
-fieldDecl(isPrivate())
-  matches 'int c;'
-
Matcher<Decl>isProtected
Matches protected C++ declarations.
-
-Given
-  class C {
-  public:    int a;
-  protected: int b;
-  private:   int c;
-  };
-fieldDecl(isProtected())
-  matches 'int b;'
-
Matcher<Decl>isPublic
Matches public C++ declarations.
-
-Given
-  class C {
-  public:    int a;
-  protected: int b;
-  private:   int c;
-  };
-fieldDecl(isPublic())
-  matches 'int a;'
-
Matcher<FloatingLiteral>equalsValueT Value
Matches literals that are equal to the given value.
-
-Example matches true (matcher = boolLiteral(equals(true)))
-  true
-
-Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
-           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
-
Matcher<FunctionDecl>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.
-
-Matches overloaded operator names specified in strings without the
-"operator" prefix: e.g. "<<".
-
-Given:
-  class A { int operator*(); };
-  const A &operator<<(const A &a, const A &b);
-  A a;
-  a << a;   <-- This matches
-
-operatorCallExpr(hasOverloadedOperatorName("<<"))) matches the specified
-line and recordDecl(hasMethod(hasOverloadedOperatorName("*"))) matches
-the declaration of A.
-
-Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
-
Matcher<FunctionDecl>isDefinition
Matches if a declaration has a body attached.
-
-Example matches A, va, fa
-  class A {};
-  class B;  Doesn't match, as it has no body.
-  int va;
-  extern int vb;  Doesn't match, as it doesn't define the variable.
-  void fa() {}
-  void fb();  Doesn't match, as it has no body.
-
-Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
-
Matcher<FunctionDecl>isDeleted
Matches deleted function declarations.
-
-Given:
-  void Func();
-  void DeletedFunc() = delete;
-functionDecl(isDeleted())
-  matches the declaration of DeletedFunc, but not Func.
-
Matcher<FunctionDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
-static member variable template instantiations.
-
-Given
-  template<typename T> void A(T t) { }
-  template<> void A(int N) { }
-functionDecl(isExplicitTemplateSpecialization())
-  matches the specialization A<int>().
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<FunctionDecl>isExternC
Matches extern "C" function declarations.
-
-Given:
-  extern "C" void f() {}
-  extern "C" { void g() {} }
-  void h() {}
-functionDecl(isExternC())
-  matches the declaration of f and g, but not the declaration h
-
Matcher<FunctionDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
-member variable template instantiations.
-
-Given
-  template <typename T> class X {}; class A {}; X<A> x;
-or
-  template <typename T> class X {}; class A {}; template class X<A>;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  matches the template instantiation of X<A>.
-
-But given
-  template <typename T>  class X {}; class A {};
-  template <> class X<A> {}; X<A> x;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  does not match, as X<A> is an explicit template specialization.
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<FunctionDecl>parameterCountIsunsigned N
Matches FunctionDecls that have a specific parameter count.
-
-Given
-  void f(int i) {}
-  void g(int i, int j) {}
-functionDecl(parameterCountIs(2))
-  matches g(int i, int j) {}
-
Matcher<IntegerLiteral>equalsValueT Value
Matches literals that are equal to the given value.
-
-Example matches true (matcher = boolLiteral(equals(true)))
-  true
-
-Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
-           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
-
Matcher<MemberExpr>isArrow
Matches member expressions that are called with '->' as opposed
-to '.'.
-
-Member calls on the implicit this pointer match as called with '->'.
-
-Given
-  class Y {
-    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
-    int a;
-    static int b;
-  };
-memberExpr(isArrow())
-  matches this->x, x, y.x, a, this->b
-
Matcher<NamedDecl>hasNamestd::string Name
Matches NamedDecl nodes that have the specified name.
-
-Supports specifying enclosing namespaces or classes by prefixing the name
-with '<enclosing>::'.
-Does not match typedefs of an underlying type with the given name.
-
-Example matches X (Name == "X")
-  class X;
-
-Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
-  namespace a { namespace b { class X; } }
-
Matcher<NamedDecl>matchesNamestd::string RegExp
Matches NamedDecl nodes whose fully qualified names contain
-a substring matched by the given RegExp.
-
-Supports specifying enclosing namespaces or classes by
-prefixing the name with '<enclosing>::'.  Does not match typedefs
-of an underlying type with the given name.
-
-Example matches X (regexp == "::X")
-  class X;
-
-Example matches X (regexp is one of "::X", "^foo::.*X", among others)
-  namespace foo { namespace bar { class X; } }
-
Matcher<QualType>asStringstd::string Name
Matches if the matched type is represented by the given string.
-
-Given
-  class Y { public: void x(); };
-  void z() { Y* y; y->x(); }
-callExpr(on(hasType(asString("class Y *"))))
-  matches y->x()
-
Matcher<QualType>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
-
-Matches a node if it equals the node previously bound to ID.
-
-Given
-  class X { int a; int b; };
-recordDecl(
-    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
-    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
-  matches the class X, as a and b have the same type.
-
-Note that when multiple matches are involved via forEach* matchers,
-equalsBoundNodes acts as a filter.
-For example:
-compoundStmt(
-    forEachDescendant(varDecl().bind("d")),
-    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
-will trigger a match for each combination of variable declaration
-and reference to that variable declaration within a compound statement.
-
Matcher<QualType>hasLocalQualifiers
Matches QualType nodes that have local CV-qualifiers attached to
-the node, not hidden within a typedef.
-
-Given
-  typedef const int const_int;
-  const_int i;
-  int *const j;
-  int *volatile k;
-  int m;
-varDecl(hasType(hasLocalQualifiers())) matches only j and k.
-i is const-qualified but the qualifier is not local.
-
Matcher<QualType>isConstQualified
Matches QualType nodes that are const-qualified, i.e., that
-include "top-level" const.
-
-Given
-  void a(int);
-  void b(int const);
-  void c(const int);
-  void d(const int*);
-  void e(int const) {};
-functionDecl(hasAnyParameter(hasType(isConstQualified())))
-  matches "void b(int const)", "void c(const int)" and
-  "void e(int const) {}". It does not match d as there
-  is no top-level const on the parameter type "const int *".
-
Matcher<QualType>isInteger
Matches QualType nodes that are of integer type.
-
-Given
-  void a(int);
-  void b(long);
-  void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger())))
-matches "a(int)", "b(long)", but not "c(double)".
-
Matcher<Stmt>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
-
-Matches a node if it equals the node previously bound to ID.
-
-Given
-  class X { int a; int b; };
-recordDecl(
-    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
-    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
-  matches the class X, as a and b have the same type.
-
-Note that when multiple matches are involved via forEach* matchers,
-equalsBoundNodes acts as a filter.
-For example:
-compoundStmt(
-    forEachDescendant(varDecl().bind("d")),
-    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
-will trigger a match for each combination of variable declaration
-and reference to that variable declaration within a compound statement.
-
Matcher<Stmt>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
-partially matching a given regex.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
-  #include "ASTMatcher.h"
-  class X {};
-ASTMatcher.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Stmt>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
-
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
-  #include <Y.h>
-  class X {};
-Y.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Stmt>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
-  #include <SystemHeader.h>
-  class X {};
-SystemHeader.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<TagDecl>isDefinition
Matches if a declaration has a body attached.
-
-Example matches A, va, fa
-  class A {};
-  class B;  Doesn't match, as it has no body.
-  int va;
-  extern int vb;  Doesn't match, as it doesn't define the variable.
-  void fa() {}
-  void fb();  Doesn't match, as it has no body.
-
-Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
-
Matcher<TemplateArgument>equalsIntegralValuestd::string Value
Matches a TemplateArgument of integral type with a given value.
-
-Note that 'Value' is a string as the template argument's value is
-an arbitrary precision integer. 'Value' must be euqal to the canonical
-representation of that integral value in base 10.
-
-Given
-  template<int T> struct A {};
-  C<42> c;
-classTemplateSpecializationDecl(
-  hasAnyTemplateArgument(equalsIntegralValue("42")))
-  matches the implicit instantiation of C in C<42>.
-
Matcher<TemplateArgument>isIntegral
Matches a TemplateArgument that is an integral value.
-
-Given
-  template<int T> struct A {};
-  C<42> c;
-classTemplateSpecializationDecl(
-  hasAnyTemplateArgument(isIntegral()))
-  matches the implicit instantiation of C in C<42>
-  with isIntegral() matching 42.
-
Matcher<TemplateSpecializationType>templateArgumentCountIsunsigned N
Matches if the number of template arguments equals N.
-
-Given
-  template<typename T> struct C {};
-  C<int> c;
-classTemplateSpecializationDecl(templateArgumentCountIs(1))
-  matches C<int>.
-
Matcher<TypeLoc>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
-partially matching a given regex.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInFileMatching("AST.*"))
-  #include "ASTMatcher.h"
-  class X {};
-ASTMatcher.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<TypeLoc>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
-
-Example matches X but not Y (matcher = recordDecl(isExpansionInMainFile())
-  #include <Y.h>
-  class X {};
-Y.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<TypeLoc>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
-
-Example matches Y but not X
-    (matcher = recordDecl(isExpansionInSystemHeader())
-  #include <SystemHeader.h>
-  class X {};
-SystemHeader.h:
-  class Y {};
-
-Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
-
Matcher<Type>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
-
-Matches a node if it equals the node previously bound to ID.
-
-Given
-  class X { int a; int b; };
-recordDecl(
-    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
-    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
-  matches the class X, as a and b have the same type.
-
-Note that when multiple matches are involved via forEach* matchers,
-equalsBoundNodes acts as a filter.
-For example:
-compoundStmt(
-    forEachDescendant(varDecl().bind("d")),
-    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
-will trigger a match for each combination of variable declaration
-and reference to that variable declaration within a compound statement.
-
Matcher<Type>voidType
Matches type void.
-
-Given
- struct S { void func(); };
-functionDecl(returns(voidType()))
-  matches "void func();"
-
Matcher<UnaryExprOrTypeTraitExpr>ofKindUnaryExprOrTypeTrait Kind
Matches unary expressions of a certain kind.
-
-Given
-  int x;
-  int s = sizeof(x) + alignof(x)
-unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
-  matches sizeof(x)
-
Matcher<UnaryOperator>hasOperatorNamestd::string Name
Matches the operator Name of operator expressions (binary or
-unary).
-
-Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
-  !(a || b)
-
Matcher<VarDecl>hasGlobalStorage
Matches a variable declaration that does not have local storage.
-
-Example matches y and z (matcher = varDecl(hasGlobalStorage())
-void f() {
-  int x;
-  static int y;
-}
-int z;
-
Matcher<VarDecl>hasLocalStorage
Matches a variable declaration that has function scope and is a
-non-static local variable.
-
-Example matches x (matcher = varDecl(hasLocalStorage())
-void f() {
-  int x;
-  static int y;
-}
-int z;
-
Matcher<VarDecl>isDefinition
Matches if a declaration has a body attached.
-
-Example matches A, va, fa
-  class A {};
-  class B;  Doesn't match, as it has no body.
-  int va;
-  extern int vb;  Doesn't match, as it doesn't define the variable.
-  void fa() {}
-  void fb();  Doesn't match, as it has no body.
-
-Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
-
Matcher<VarDecl>isExceptionVariable
Matches if a variable declaration is for a C++ catch handler or Objective-C @catch variable.
-
-Example matches x (matcher = varDecl(isExceptionVariable())
-  void f(int y) {
-    try {
-    } catch (int x) {
-    }
-  }
-
Matcher<VarDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
-static member variable template instantiations.
-
-Given
-  template<typename T> void A(T t) { }
-  template<> void A(int N) { }
-functionDecl(isExplicitTemplateSpecialization())
-  matches the specialization A<int>().
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<VarDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
-member variable template instantiations.
-
-Given
-  template <typename T> class X {}; class A {}; X<A> x;
-or
-  template <typename T> class X {}; class A {}; template class X<A>;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  matches the template instantiation of X<A>.
-
-But given
-  template <typename T>  class X {}; class A {};
-  template <> class X<A> {}; X<A> x;
-recordDecl(hasName("::X"), isTemplateInstantiation())
-  does not match, as X<A> is an explicit template specialization.
-
-Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
-
Matcher<internal::Matcher<Decl>>isInstantiated
Matches declarations that are template instantiations or are inside
-template instantiations.
-
-Given
-  template<typename T> void A(T t) { T i; }
-  A(0);
-  A(0U);
-functionDecl(isInstantiated())
-  matches 'A(int) {...};' and 'A(unsigned) {...}'.
-
Matcher<internal::Matcher<Stmt>>isInTemplateInstantiation
Matches statements inside of a template instantiation.
-
-Given
-  int j;
-  template<typename T> void A(T t) { T i; j += 42;}
-  A(0);
-  A(0U);
-declStmt(isInTemplateInstantiation())
-  matches 'int i;' and 'unsigned i'.
-unless(stmt(isInTemplateInstantiation()))
-  will NOT match j += 42; as it's shared between the template definition and
-  instantiation.
-
- - -

AST Traversal Matchers

- - -

Traversal matchers specify the relationship to other nodes that are -reachable from the current node.

- -

Note that there are special traversal matchers (has, hasDescendant, forEach and -forEachDescendant) which work on all nodes and allow users to write more generic -match expressions.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Return typeNameParameters
Matcher<*>eachOfMatcher<*>, ..., Matcher<*>
Matches if any of the given matchers matches.
-
-Unlike anyOf, eachOf will generate a match result for each
-matching submatcher.
-
-For example, in:
-  class A { int a; int b; };
-The matcher:
-  recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
-                    has(fieldDecl(hasName("b")).bind("v"))))
-will generate two results binding "v", the first of which binds
-the field declaration of a, the second the field declaration of
-b.
-
-Usable as: Any Matcher
-
Matcher<*>forEachDescendantMatcher<*>
Matches AST nodes that have descendant AST nodes that match the
-provided matcher.
-
-Example matches X, A, B, C
-    (matcher = recordDecl(forEachDescendant(recordDecl(hasName("X")))))
-  class X {};  Matches X, because X::X is a class of name X inside X.
-  class A { class X {}; };
-  class B { class C { class X {}; }; };
-
-DescendantT must be an AST base type.
-
-As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
-each result that matches instead of only on the first one.
-
-Note: Recursively combined ForEachDescendant can cause many matches:
-  recordDecl(forEachDescendant(recordDecl(forEachDescendant(recordDecl()))))
-will match 10 times (plus injected class name matches) on:
-  class A { class B { class C { class D { class E {}; }; }; }; };
-
-Usable as: Any Matcher
-
Matcher<*>forEachMatcher<*>
Matches AST nodes that have child AST nodes that match the
-provided matcher.
-
-Example matches X, Y (matcher = recordDecl(forEach(recordDecl(hasName("X")))
-  class X {};  Matches X, because X::X is a class of name X inside X.
-  class Y { class X {}; };
-  class Z { class Y { class X {}; }; };  Does not match Z.
-
-ChildT must be an AST base type.
-
-As opposed to 'has', 'forEach' will cause a match for each result that
-matches instead of only on the first one.
-
-Usable as: Any Matcher
-
Matcher<*>hasAncestorMatcher<*>
Matches AST nodes that have an ancestor that matches the provided
-matcher.
-
-Given
-void f() { if (true) { int x = 42; } }
-void g() { for (;;) { int x = 43; } }
-expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43.
-
-Usable as: Any Matcher
-
Matcher<*>hasDescendantMatcher<*>
Matches AST nodes that have descendant AST nodes that match the
-provided matcher.
-
-Example matches X, Y, Z
-    (matcher = recordDecl(hasDescendant(recordDecl(hasName("X")))))
-  class X {};  Matches X, because X::X is a class of name X inside X.
-  class Y { class X {}; };
-  class Z { class Y { class X {}; }; };
-
-DescendantT must be an AST base type.
-
-Usable as: Any Matcher
-
Matcher<*>hasMatcher<*>
Matches AST nodes that have child AST nodes that match the
-provided matcher.
-
-Example matches X, Y (matcher = recordDecl(has(recordDecl(hasName("X")))
-  class X {};  Matches X, because X::X is a class of name X inside X.
-  class Y { class X {}; };
-  class Z { class Y { class X {}; }; };  Does not match Z.
-
-ChildT must be an AST base type.
-
-Usable as: Any Matcher
-
Matcher<*>hasParentMatcher<*>
Matches AST nodes that have a parent that matches the provided
-matcher.
-
-Given
-void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }
-compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
-
-Usable as: Any Matcher
-
Matcher<ArraySubscriptExpr>hasBaseMatcher<Expr> InnerMatcher
Matches the base expression of an array subscript expression.
-
-Given
-  int i[5];
-  void f() { i[1] = 42; }
-arraySubscriptExpression(hasBase(implicitCastExpr(
-    hasSourceExpression(declRefExpr()))))
-  matches i[1] with the declRefExpr() matching i
-
Matcher<ArraySubscriptExpr>hasIndexMatcher<Expr> InnerMatcher
Matches the index expression of an array subscript expression.
-
-Given
-  int i[5];
-  void f() { i[1] = 42; }
-arraySubscriptExpression(hasIndex(integerLiteral()))
-  matches i[1] with the integerLiteral() matching 1
-
Matcher<ArrayTypeLoc>hasElementTypeLocMatcher<TypeLoc>
Matches arrays and C99 complex types that have a specific element
-type.
-
-Given
-  struct A {};
-  A a[7];
-  int b[7];
-arrayType(hasElementType(builtinType()))
-  matches "int b[7]"
-
-Usable as: Matcher<ArrayType>, Matcher<ComplexType>
-
Matcher<ArrayType>hasElementTypeMatcher<Type>
Matches arrays and C99 complex types that have a specific element
-type.
-
-Given
-  struct A {};
-  A a[7];
-  int b[7];
-arrayType(hasElementType(builtinType()))
-  matches "int b[7]"
-
-Usable as: Matcher<ArrayType>, Matcher<ComplexType>
-
Matcher<AtomicTypeLoc>hasValueTypeLocMatcher<TypeLoc>
Matches atomic types with a specific value type.
-
-Given
-  _Atomic(int) i;
-  _Atomic(float) f;
-atomicType(hasValueType(isInteger()))
- matches "_Atomic(int) i"
-
-Usable as: Matcher<AtomicType>
-
Matcher<AtomicType>hasValueTypeMatcher<Type>
Matches atomic types with a specific value type.
-
-Given
-  _Atomic(int) i;
-  _Atomic(float) f;
-atomicType(hasValueType(isInteger()))
- matches "_Atomic(int) i"
-
-Usable as: Matcher<AtomicType>
-
Matcher<AutoType>hasDeducedTypeMatcher<Type>
Matches AutoType nodes where the deduced type is a specific type.
-
-Note: There is no TypeLoc for the deduced type and thus no
-getDeducedLoc() matcher.
-
-Given
-  auto a = 1;
-  auto b = 2.0;
-autoType(hasDeducedType(isInteger()))
-  matches "auto a"
-
-Usable as: Matcher<AutoType>
-
Matcher<BinaryOperator>hasEitherOperandMatcher<Expr> InnerMatcher
Matches if either the left hand side or the right hand side of a
-binary operator matches.
-
Matcher<BinaryOperator>hasLHSMatcher<Expr> InnerMatcher
Matches the left hand side of binary operator expressions.
-
-Example matches a (matcher = binaryOperator(hasLHS()))
-  a || b
-
Matcher<BinaryOperator>hasRHSMatcher<Expr> InnerMatcher
Matches the right hand side of binary operator expressions.
-
-Example matches b (matcher = binaryOperator(hasRHS()))
-  a || b
-
Matcher<BlockPointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<BlockPointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<CXXConstructExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
-expression.
-
-Given
-  void x(int, int, int) { int y; x(1, y, 42); }
-callExpr(hasAnyArgument(declRefExpr()))
-  matches x(1, y, 42)
-with hasAnyArgument(...)
-  matching y
-
-FIXME: Currently this will ignore parentheses and implicit casts on
-the argument before applying the inner matcher. We'll want to remove
-this to allow for greater control by the user once ignoreImplicit()
-has been implemented.
-
Matcher<CXXConstructExpr>hasArgumentunsigned N, Matcher<Expr> InnerMatcher
Matches the n'th argument of a call expression or a constructor
-call expression.
-
-Example matches y in x(y)
-    (matcher = callExpr(hasArgument(0, declRefExpr())))
-  void x(int) { int y; x(y); }
-
Matcher<CXXConstructExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<CXXConstructorDecl>forEachConstructorInitializerMatcher<CXXCtorInitializer> InnerMatcher
Matches each constructor initializer in a constructor definition.
-
-Given
-  class A { A() : i(42), j(42) {} int i; int j; };
-constructorDecl(forEachConstructorInitializer(forField(decl().bind("x"))))
-  will trigger two matches, binding for 'i' and 'j' respectively.
-
Matcher<CXXConstructorDecl>hasAnyConstructorInitializerMatcher<CXXCtorInitializer> InnerMatcher
Matches a constructor initializer.
-
-Given
-  struct Foo {
-    Foo() : foo_(1) { }
-    int foo_;
-  };
-recordDecl(has(constructorDecl(hasAnyConstructorInitializer(anything()))))
-  record matches Foo, hasAnyConstructorInitializer matches foo_(1)
-
Matcher<CXXCtorInitializer>forFieldMatcher<FieldDecl> InnerMatcher
Matches the field declaration of a constructor initializer.
-
-Given
-  struct Foo {
-    Foo() : foo_(1) { }
-    int foo_;
-  };
-recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
-    forField(hasName("foo_"))))))
-  matches Foo
-with forField matching foo_
-
Matcher<CXXCtorInitializer>withInitializerMatcher<Expr> InnerMatcher
Matches the initializer expression of a constructor initializer.
-
-Given
-  struct Foo {
-    Foo() : foo_(1) { }
-    int foo_;
-  };
-recordDecl(has(constructorDecl(hasAnyConstructorInitializer(
-    withInitializer(integerLiteral(equals(1)))))))
-  matches Foo
-with withInitializer matching (1)
-
Matcher<CXXForRangeStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
-a given body.
-
-Given
-  for (;;) {}
-hasBody(compoundStmt())
-  matches 'for (;;) {}'
-with compoundStmt()
-  matching '{}'
-
Matcher<CXXForRangeStmt>hasLoopVariableMatcher<VarDecl> InnerMatcher
Matches the initialization statement of a for loop.
-
-Example:
-    forStmt(hasLoopVariable(anything()))
-matches 'int x' in
-    for (int x : a) { }
-
Matcher<CXXForRangeStmt>hasRangeInitMatcher<Expr> InnerMatcher
Matches the range initialization statement of a for loop.
-
-Example:
-    forStmt(hasRangeInit(anything()))
-matches 'a' in
-    for (int x : a) { }
-
Matcher<CXXMemberCallExpr>onImplicitObjectArgumentMatcher<Expr> InnerMatcher
Matcher<CXXMemberCallExpr>onMatcher<Expr> InnerMatcher
Matches on the implicit object argument of a member call expression.
-
-Example matches y.x() (matcher = callExpr(on(hasType(recordDecl(hasName("Y"))))))
-  class Y { public: void x(); };
-  void z() { Y y; y.x(); }",
-
-FIXME: Overload to allow directly matching types?
-
Matcher<CXXMemberCallExpr>thisPointerTypeMatcher<Decl> InnerMatcher
Overloaded to match the type's declaration.
-
Matcher<CXXMemberCallExpr>thisPointerTypeMatcher<QualType> InnerMatcher
Matches if the expression's type either matches the specified
-matcher, or is a pointer to a type that matches the InnerMatcher.
-
Matcher<CXXMethodDecl>ofClassMatcher<CXXRecordDecl> InnerMatcher
Matches the class declaration that the given method declaration
-belongs to.
-
-FIXME: Generalize this for other kinds of declarations.
-FIXME: What other kind of declarations would we need to generalize
-this to?
-
-Example matches A() in the last line
-    (matcher = constructExpr(hasDeclaration(methodDecl(
-        ofClass(hasName("A"))))))
-  class A {
-   public:
-    A();
-  };
-  A a = A();
-
Matcher<CXXRecordDecl>hasMethodMatcher<CXXMethodDecl> InnerMatcher
Matches the first method of a class or struct that satisfies InnerMatcher.
-
-Given:
-  class A { void func(); };
-  class B { void member(); };
-
-recordDecl(hasMethod(hasName("func"))) matches the declaration of A
-but not B.
-
Matcher<CXXRecordDecl>isDerivedFromMatcher<NamedDecl> Base
Matches C++ classes that are directly or indirectly derived from
-a class matching Base.
-
-Note that a class is not considered to be derived from itself.
-
-Example matches Y, Z, C (Base == hasName("X"))
-  class X;
-  class Y : public X {};  directly derived
-  class Z : public Y {};  indirectly derived
-  typedef X A;
-  typedef A B;
-  class C : public B {};  derived from a typedef of X
-
-In the following example, Bar matches isDerivedFrom(hasName("X")):
-  class Foo;
-  typedef Foo X;
-  class Bar : public Foo {};  derived from a type that X is a typedef of
-
Matcher<CXXRecordDecl>isSameOrDerivedFromMatcher<NamedDecl> Base
Similar to isDerivedFrom(), but also matches classes that directly
-match Base.
-
Matcher<CallExpr>calleeMatcher<Decl> InnerMatcher
Matches if the call expression's callee's declaration matches the
-given matcher.
-
-Example matches y.x() (matcher = callExpr(callee(methodDecl(hasName("x")))))
-  class Y { public: void x(); };
-  void z() { Y y; y.x(); }
-
Matcher<CallExpr>calleeMatcher<Stmt> InnerMatcher
Matches if the call expression's callee expression matches.
-
-Given
-  class Y { void x() { this->x(); x(); Y y; y.x(); } };
-  void f() { f(); }
-callExpr(callee(expr()))
-  matches this->x(), x(), y.x(), f()
-with callee(...)
-  matching this->x, x, y.x, f respectively
-
-Note: Callee cannot take the more general internal::Matcher<Expr>
-because this introduces ambiguous overloads with calls to Callee taking a
-internal::Matcher<Decl>, as the matcher hierarchy is purely
-implemented in terms of implicit casts.
-
Matcher<CallExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
-expression.
-
-Given
-  void x(int, int, int) { int y; x(1, y, 42); }
-callExpr(hasAnyArgument(declRefExpr()))
-  matches x(1, y, 42)
-with hasAnyArgument(...)
-  matching y
-
-FIXME: Currently this will ignore parentheses and implicit casts on
-the argument before applying the inner matcher. We'll want to remove
-this to allow for greater control by the user once ignoreImplicit()
-has been implemented.
-
Matcher<CallExpr>hasArgumentunsigned N, Matcher<Expr> InnerMatcher
Matches the n'th argument of a call expression or a constructor
-call expression.
-
-Example matches y in x(y)
-    (matcher = callExpr(hasArgument(0, declRefExpr())))
-  void x(int) { int y; x(y); }
-
Matcher<CallExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<CaseStmt>hasCaseConstantMatcher<Expr> InnerMatcher
If the given case statement does not use the GNU case range
-extension, matches the constant given in the statement.
-
-Given
-  switch (1) { case 1: case 1+1: case 3 ... 4: ; }
-caseStmt(hasCaseConstant(integerLiteral()))
-  matches "case 1:"
-
Matcher<CastExpr>hasSourceExpressionMatcher<Expr> InnerMatcher
Matches if the cast's source expression matches the given matcher.
-
-Example: matches "a string" (matcher =
-                                 hasSourceExpression(constructExpr()))
-class URL { URL(string); };
-URL url = "a string";
-
Matcher<ClassTemplateSpecializationDecl>hasAnyTemplateArgumentMatcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations that have at least one
-TemplateArgument matching the given InnerMatcher.
-
-Given
-  template<typename T> class A {};
-  template<> class A<double> {};
-  A<int> a;
-classTemplateSpecializationDecl(hasAnyTemplateArgument(
-    refersToType(asString("int"))))
-  matches the specialization A<int>
-
Matcher<ClassTemplateSpecializationDecl>hasTemplateArgumentunsigned N, Matcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations where the n'th TemplateArgument
-matches the given InnerMatcher.
-
-Given
-  template<typename T, typename U> class A {};
-  A<bool, int> b;
-  A<int, bool> c;
-classTemplateSpecializationDecl(hasTemplateArgument(
-    1, refersToType(asString("int"))))
-  matches the specialization A<bool, int>
-
Matcher<ComplexTypeLoc>hasElementTypeLocMatcher<TypeLoc>
Matches arrays and C99 complex types that have a specific element
-type.
-
-Given
-  struct A {};
-  A a[7];
-  int b[7];
-arrayType(hasElementType(builtinType()))
-  matches "int b[7]"
-
-Usable as: Matcher<ArrayType>, Matcher<ComplexType>
-
Matcher<ComplexType>hasElementTypeMatcher<Type>
Matches arrays and C99 complex types that have a specific element
-type.
-
-Given
-  struct A {};
-  A a[7];
-  int b[7];
-arrayType(hasElementType(builtinType()))
-  matches "int b[7]"
-
-Usable as: Matcher<ArrayType>, Matcher<ComplexType>
-
Matcher<CompoundStmt>hasAnySubstatementMatcher<Stmt> InnerMatcher
Matches compound statements where at least one substatement matches
-a given matcher.
-
-Given
-  { {}; 1+2; }
-hasAnySubstatement(compoundStmt())
-  matches '{ {}; 1+2; }'
-with compoundStmt()
-  matching '{}'
-
Matcher<ConditionalOperator>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
-or conditional operator.
-
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
-  if (true) {}
-
Matcher<ConditionalOperator>hasFalseExpressionMatcher<Expr> InnerMatcher
Matches the false branch expression of a conditional operator.
-
-Example matches b
-  condition ? a : b
-
Matcher<ConditionalOperator>hasTrueExpressionMatcher<Expr> InnerMatcher
Matches the true branch expression of a conditional operator.
-
-Example matches a
-  condition ? a : b
-
Matcher<DeclRefExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<DeclRefExpr>throughUsingDeclMatcher<UsingShadowDecl> InnerMatcher
Matches a DeclRefExpr that refers to a declaration through a
-specific using shadow declaration.
-
-FIXME: This currently only works for functions. Fix.
-
-Given
-  namespace a { void f() {} }
-  using a::f;
-  void g() {
-    f();     Matches this ..
-    a::f();  .. but not this.
-  }
-declRefExpr(throughUsingDeclaration(anything()))
-  matches f()
-
Matcher<DeclRefExpr>toMatcher<Decl> InnerMatcher
Matches a DeclRefExpr that refers to a declaration that matches the
-specified matcher.
-
-Example matches x in if(x)
-    (matcher = declRefExpr(to(varDecl(hasName("x")))))
-  bool x;
-  if (x) {}
-
Matcher<DeclStmt>containsDeclarationunsigned N, Matcher<Decl> InnerMatcher
Matches the n'th declaration of a declaration statement.
-
-Note that this does not work for global declarations because the AST
-breaks up multiple-declaration DeclStmt's into multiple single-declaration
-DeclStmt's.
-Example: Given non-global declarations
-  int a, b = 0;
-  int c;
-  int d = 2, e;
-declStmt(containsDeclaration(
-      0, varDecl(hasInitializer(anything()))))
-  matches only 'int d = 2, e;', and
-declStmt(containsDeclaration(1, varDecl()))
-  matches 'int a, b = 0' as well as 'int d = 2, e;'
-  but 'int c;' is not matched.
-
Matcher<DeclStmt>hasSingleDeclMatcher<Decl> InnerMatcher
Matches the Decl of a DeclStmt which has a single declaration.
-
-Given
-  int a, b;
-  int c;
-declStmt(hasSingleDecl(anything()))
-  matches 'int c;' but not 'int a, b;'.
-
Matcher<DeclaratorDecl>hasTypeLocMatcher<TypeLoc> Inner
Matches if the type location of the declarator decl's type matches
-the inner matcher.
-
-Given
-  int x;
-declaratorDecl(hasTypeLoc(loc(asString("int"))))
-  matches int x
-
Matcher<Decl>hasDeclContextMatcher<Decl> InnerMatcher
Matches declarations whose declaration context, interpreted as a
-Decl, matches InnerMatcher.
-
-Given
-  namespace N {
-    namespace M {
-      class D {};
-    }
-  }
-
-recordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
-declaration of class D.
-
Matcher<DoStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
-a given body.
-
-Given
-  for (;;) {}
-hasBody(compoundStmt())
-  matches 'for (;;) {}'
-with compoundStmt()
-  matching '{}'
-
Matcher<DoStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
-or conditional operator.
-
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
-  if (true) {}
-
Matcher<ElaboratedType>hasQualifierMatcher<NestedNameSpecifier> InnerMatcher
Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
-matches InnerMatcher if the qualifier exists.
-
-Given
-  namespace N {
-    namespace M {
-      class D {};
-    }
-  }
-  N::M::D d;
-
-elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
-matches the type of the variable declaration of d.
-
Matcher<ElaboratedType>namesTypeMatcher<QualType> InnerMatcher
Matches ElaboratedTypes whose named type matches InnerMatcher.
-
-Given
-  namespace N {
-    namespace M {
-      class D {};
-    }
-  }
-  N::M::D d;
-
-elaboratedType(namesType(recordType(
-hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-declaration of d.
-
Matcher<EnumType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<ExplicitCastExpr>hasDestinationTypeMatcher<QualType> InnerMatcher
Matches casts whose destination type matches a given matcher.
-
-(Note: Clang's AST refers to other conversions as "casts" too, and calls
-actual casts "explicit" casts.)
-
Matcher<Expr>hasTypeMatcher<Decl> InnerMatcher
Overloaded to match the declaration of the expression's or value
-declaration's type.
-
-In case of a value declaration (for example a variable declaration),
-this resolves one layer of indirection. For example, in the value
-declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
-while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
-of x."
-
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
- class X {};
- void y(X &x) { x; X z; }
-
-Usable as: Matcher<Expr>, Matcher<ValueDecl>
-
Matcher<Expr>hasTypeMatcher<QualType> InnerMatcher
Matches if the expression's or declaration's type matches a type
-matcher.
-
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
- class X {};
- void y(X &x) { x; X z; }
-
Matcher<Expr>ignoringImpCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after any implicit casts
-are stripped off.
-
-Parentheses and explicit casts are not discarded.
-Given
-  int arr[5];
-  int a = 0;
-  char b = 0;
-  const int c = a;
-  int *d = arr;
-  long e = (long) 0l;
-The matchers
-   varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
-   varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
-would match the declarations for a, b, c, and d, but not e.
-While
-   varDecl(hasInitializer(integerLiteral()))
-   varDecl(hasInitializer(declRefExpr()))
-only match the declarations for b, c, and d.
-
Matcher<Expr>ignoringParenCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after parentheses and
-casts are stripped off.
-
-Implicit and non-C Style casts are also discarded.
-Given
-  int a = 0;
-  char b = (0);
-  void* c = reinterpret_cast<char*>(0);
-  char d = char(0);
-The matcher
-   varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
-would match the declarations for a, b, c, and d.
-while
-   varDecl(hasInitializer(integerLiteral()))
-only match the declaration for a.
-
Matcher<Expr>ignoringParenImpCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after implicit casts and
-parentheses are stripped off.
-
-Explicit casts are not discarded.
-Given
-  int arr[5];
-  int a = 0;
-  char b = (0);
-  const int c = a;
-  int *d = (arr);
-  long e = ((long) 0l);
-The matchers
-   varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
-   varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
-would match the declarations for a, b, c, and d, but not e.
-while
-   varDecl(hasInitializer(integerLiteral()))
-   varDecl(hasInitializer(declRefExpr()))
-would only match the declaration for a.
-
Matcher<ForStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
-a given body.
-
-Given
-  for (;;) {}
-hasBody(compoundStmt())
-  matches 'for (;;) {}'
-with compoundStmt()
-  matching '{}'
-
Matcher<ForStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
-or conditional operator.
-
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
-  if (true) {}
-
Matcher<ForStmt>hasIncrementMatcher<Stmt> InnerMatcher
Matches the increment statement of a for loop.
-
-Example:
-    forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
-matches '++x' in
-    for (x; x < N; ++x) { }
-
Matcher<ForStmt>hasLoopInitMatcher<Stmt> InnerMatcher
Matches the initialization statement of a for loop.
-
-Example:
-    forStmt(hasLoopInit(declStmt()))
-matches 'int x = 0' in
-    for (int x = 0; x < N; ++x) { }
-
Matcher<FunctionDecl>hasAnyParameterMatcher<ParmVarDecl> InnerMatcher
Matches any parameter of a function declaration.
-
-Does not match the 'this' parameter of a method.
-
-Given
-  class X { void f(int x, int y, int z) {} };
-methodDecl(hasAnyParameter(hasName("y")))
-  matches f(int x, int y, int z) {}
-with hasAnyParameter(...)
-  matching int y
-
Matcher<FunctionDecl>hasParameterunsigned N, Matcher<ParmVarDecl> InnerMatcher
Matches the n'th parameter of a function declaration.
-
-Given
-  class X { void f(int x) {} };
-methodDecl(hasParameter(0, hasType(varDecl())))
-  matches f(int x) {}
-with hasParameter(...)
-  matching int x
-
Matcher<FunctionDecl>returnsMatcher<QualType> InnerMatcher
Matches the return type of a function declaration.
-
-Given:
-  class X { int f() { return 1; } };
-methodDecl(returns(asString("int")))
-  matches int f() { return 1; }
-
Matcher<IfStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
-or conditional operator.
-
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
-  if (true) {}
-
Matcher<IfStmt>hasConditionVariableStatementMatcher<DeclStmt> InnerMatcher
Matches the condition variable statement in an if statement.
-
-Given
-  if (A* a = GetAPointer()) {}
-hasConditionVariableStatement(...)
-  matches 'A* a = GetAPointer()'.
-
Matcher<IfStmt>hasElseMatcher<Stmt> InnerMatcher
Matches the else-statement of an if statement.
-
-Examples matches the if statement
-  (matcher = ifStmt(hasElse(boolLiteral(equals(true)))))
-  if (false) false; else true;
-
Matcher<IfStmt>hasThenMatcher<Stmt> InnerMatcher
Matches the then-statement of an if statement.
-
-Examples matches the if statement
-  (matcher = ifStmt(hasThen(boolLiteral(equals(true)))))
-  if (false) true; else false;
-
Matcher<ImplicitCastExpr>hasImplicitDestinationTypeMatcher<QualType> InnerMatcher
Matches implicit casts whose destination type matches a given
-matcher.
-
-FIXME: Unit test this matcher
-
Matcher<InjectedClassNameType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<LabelStmt>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<MemberExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<MemberExpr>hasObjectExpressionMatcher<Expr> InnerMatcher
Matches a member expression where the object expression is
-matched by a given matcher.
-
-Given
-  struct X { int m; };
-  void f(X x) { x.m; m; }
-memberExpr(hasObjectExpression(hasType(recordDecl(hasName("X")))))))
-  matches "x.m" and "m"
-with hasObjectExpression(...)
-  matching "x" and the implicit object expression of "m" which has type X*.
-
Matcher<MemberExpr>memberMatcher<ValueDecl> InnerMatcher
Matches a member expression where the member is matched by a
-given matcher.
-
-Given
-  struct { int first, second; } first, second;
-  int i(second.first);
-  int j(first.second);
-memberExpr(member(hasName("first")))
-  matches second.first
-  but not first.second (because the member name there is "second").
-
Matcher<MemberPointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<MemberPointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<NestedNameSpecifierLoc>hasPrefixMatcher<NestedNameSpecifierLoc> InnerMatcher
Matches on the prefix of a NestedNameSpecifierLoc.
-
-Given
-  struct A { struct B { struct C {}; }; };
-  A::B::C c;
-nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))
-  matches "A::"
-
Matcher<NestedNameSpecifierLoc>specifiesTypeLocMatcher<TypeLoc> InnerMatcher
Matches nested name specifier locs that specify a type matching the
-given TypeLoc.
-
-Given
-  struct A { struct B { struct C {}; }; };
-  A::B::C c;
-nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(
-  hasDeclaration(recordDecl(hasName("A")))))))
-  matches "A::"
-
Matcher<NestedNameSpecifier>hasPrefixMatcher<NestedNameSpecifier> InnerMatcher
Matches on the prefix of a NestedNameSpecifier.
-
-Given
-  struct A { struct B { struct C {}; }; };
-  A::B::C c;
-nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and
-  matches "A::"
-
Matcher<NestedNameSpecifier>specifiesNamespaceMatcher<NamespaceDecl> InnerMatcher
Matches nested name specifiers that specify a namespace matching the
-given namespace matcher.
-
-Given
-  namespace ns { struct A {}; }
-  ns::A a;
-nestedNameSpecifier(specifiesNamespace(hasName("ns")))
-  matches "ns::"
-
Matcher<NestedNameSpecifier>specifiesTypeMatcher<QualType> InnerMatcher
Matches nested name specifiers that specify a type matching the
-given QualType matcher without qualifiers.
-
-Given
-  struct A { struct B { struct C {}; }; };
-  A::B::C c;
-nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A")))))
-  matches "A::"
-
Matcher<ParenType>innerTypeMatcher<Type>
Matches ParenType nodes where the inner type is a specific type.
-
-Given
-  int (*ptr_to_array)[4];
-  int (*ptr_to_func)(int);
-
-varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches
-ptr_to_func but not ptr_to_array.
-
-Usable as: Matcher<ParenType>
-
Matcher<PointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<PointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<QualType>hasCanonicalTypeMatcher<QualType> InnerMatcher
Matches QualTypes whose canonical type matches InnerMatcher.
-
-Given:
-  typedef int &int_ref;
-  int a;
-  int_ref b = a;
-
-varDecl(hasType(qualType(referenceType()))))) will not match the
-declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.
-
Matcher<QualType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<QualType>pointsToMatcher<Decl> InnerMatcher
Overloaded to match the pointee type's declaration.
-
Matcher<QualType>pointsToMatcher<QualType> InnerMatcher
Matches if the matched type is a pointer type and the pointee type
-matches the specified matcher.
-
-Example matches y->x()
-    (matcher = callExpr(on(hasType(pointsTo(recordDecl(hasName("Y")))))))
-  class Y { public: void x(); };
-  void z() { Y *y; y->x(); }
-
Matcher<QualType>referencesMatcher<Decl> InnerMatcher
Overloaded to match the referenced type's declaration.
-
Matcher<QualType>referencesMatcher<QualType> InnerMatcher
Matches if the matched type is a reference type and the referenced
-type matches the specified matcher.
-
-Example matches X &x and const X &y
-    (matcher = varDecl(hasType(references(recordDecl(hasName("X"))))))
-  class X {
-    void a(X b) {
-      X &x = b;
-      const X &y = b;
-    }
-  };
-
Matcher<RecordType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<ReferenceTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<ReferenceType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
-pointee matches a given matcher.
-
-Given
-  int *a;
-  int const *b;
-  float const *f;
-pointerType(pointee(isConstQualified(), isInteger()))
-  matches "int const *b"
-
-Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
-  Matcher<PointerType>, Matcher<ReferenceType>
-
Matcher<Stmt>alignOfExprMatcher<UnaryExprOrTypeTraitExpr> InnerMatcher
Same as unaryExprOrTypeTraitExpr, but only matching
-alignof.
-
Matcher<Stmt>sizeOfExprMatcher<UnaryExprOrTypeTraitExpr> InnerMatcher
Same as unaryExprOrTypeTraitExpr, but only matching
-sizeof.
-
Matcher<SwitchStmt>forEachSwitchCaseMatcher<SwitchCase> InnerMatcher
Matches each case or default statement belonging to the given switch
-statement. This matcher may produce multiple matches.
-
-Given
-  switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } }
-switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s")
-  matches four times, with "c" binding each of "case 1:", "case 2:",
-"case 3:" and "case 4:", and "s" respectively binding "switch (1)",
-"switch (1)", "switch (2)" and "switch (2)".
-
Matcher<TagType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<TemplateArgument>isExprMatcher<Expr> InnerMatcher
Matches a sugar TemplateArgument that refers to a certain expression.
-
-Given
-  template<typename T> struct A {};
-  struct B { B* next; };
-  A<&B::next> a;
-templateSpecializationType(hasAnyTemplateArgument(
-  isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))
-  matches the specialization A<&B::next> with fieldDecl(...) matching
-    B::next
-
Matcher<TemplateArgument>refersToDeclarationMatcher<Decl> InnerMatcher
Matches a canonical TemplateArgument that refers to a certain
-declaration.
-
-Given
-  template<typename T> struct A {};
-  struct B { B* next; };
-  A<&B::next> a;
-classTemplateSpecializationDecl(hasAnyTemplateArgument(
-    refersToDeclaration(fieldDecl(hasName("next"))))
-  matches the specialization A<&B::next> with fieldDecl(...) matching
-    B::next
-
Matcher<TemplateArgument>refersToIntegralTypeMatcher<QualType> InnerMatcher
Matches a TemplateArgument that referes to an integral type.
-
-Given
-  template<int T> struct A {};
-  C<42> c;
-classTemplateSpecializationDecl(
-  hasAnyTemplateArgument(refersToIntegralType(asString("int"))))
-  matches the implicit instantiation of C in C<42>.
-
Matcher<TemplateArgument>refersToTypeMatcher<QualType> InnerMatcher
Matches a TemplateArgument that refers to a certain type.
-
-Given
-  struct X {};
-  template<typename T> struct A {};
-  A<X> a;
-classTemplateSpecializationDecl(hasAnyTemplateArgument(
-    refersToType(class(hasName("X")))))
-  matches the specialization A<X>
-
Matcher<TemplateSpecializationType>hasAnyTemplateArgumentMatcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations that have at least one
-TemplateArgument matching the given InnerMatcher.
-
-Given
-  template<typename T> class A {};
-  template<> class A<double> {};
-  A<int> a;
-classTemplateSpecializationDecl(hasAnyTemplateArgument(
-    refersToType(asString("int"))))
-  matches the specialization A<int>
-
Matcher<TemplateSpecializationType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<TemplateSpecializationType>hasTemplateArgumentunsigned N, Matcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations where the n'th TemplateArgument
-matches the given InnerMatcher.
-
-Given
-  template<typename T, typename U> class A {};
-  A<bool, int> b;
-  A<int, bool> c;
-classTemplateSpecializationDecl(hasTemplateArgument(
-    1, refersToType(asString("int"))))
-  matches the specialization A<bool, int>
-
Matcher<TemplateTypeParmType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<T>findAllMatcher<T> Matcher
Matches if the node or any descendant matches.
-
-Generates results for each match.
-
-For example, in:
-  class A { class B {}; class C {}; };
-The matcher:
-  recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("m")))
-will generate results for A, B and C.
-
-Usable as: Any Matcher
-
Matcher<TypedefType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<UnaryExprOrTypeTraitExpr>hasArgumentOfTypeMatcher<QualType> InnerMatcher
Matches unary expressions that have a specific type of argument.
-
-Given
-  int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
-unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
-  matches sizeof(a) and alignof(c)
-
Matcher<UnaryOperator>hasUnaryOperandMatcher<Expr> InnerMatcher
Matches if the operand of a unary operator matches.
-
-Example matches true (matcher = hasUnaryOperand(boolLiteral(equals(true))))
-  !true
-
Matcher<UnresolvedUsingType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
-matches the given matcher.
-
-The associated declaration is:
-- for type nodes, the declaration of the underlying type
-- for CallExpr, the declaration of the callee
-- for MemberExpr, the declaration of the referenced member
-- for CXXConstructExpr, the declaration of the constructor
-
-Also usable as Matcher<T> for any T supporting the getDecl() member
-function. e.g. various subtypes of clang::Type and various expressions.
-
-Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
-  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
-  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
-  Matcher<RecordType>, Matcher<TagType>,
-  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
-  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
-
Matcher<UsingDecl>hasAnyUsingShadowDeclMatcher<UsingShadowDecl> InnerMatcher
Matches any using shadow declaration.
-
-Given
-  namespace X { void b(); }
-  using X::b;
-usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
-  matches using X::b 
Matcher<UsingShadowDecl>hasTargetDeclMatcher<NamedDecl> InnerMatcher
Matches a using shadow declaration where the target declaration is
-matched by the given matcher.
-
-Given
-  namespace X { int a; void b(); }
-  using X::a;
-  using X::b;
-usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
-  matches using X::b but not using X::a 
Matcher<ValueDecl>hasTypeMatcher<Decl> InnerMatcher
Overloaded to match the declaration of the expression's or value
-declaration's type.
-
-In case of a value declaration (for example a variable declaration),
-this resolves one layer of indirection. For example, in the value
-declaration "X x;", recordDecl(hasName("X")) matches the declaration of X,
-while varDecl(hasType(recordDecl(hasName("X")))) matches the declaration
-of x."
-
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
- class X {};
- void y(X &x) { x; X z; }
-
-Usable as: Matcher<Expr>, Matcher<ValueDecl>
-
Matcher<ValueDecl>hasTypeMatcher<QualType> InnerMatcher
Matches if the expression's or declaration's type matches a type
-matcher.
-
-Example matches x (matcher = expr(hasType(recordDecl(hasName("X")))))
-            and z (matcher = varDecl(hasType(recordDecl(hasName("X")))))
- class X {};
- void y(X &x) { x; X z; }
-
Matcher<VarDecl>hasInitializerMatcher<Expr> InnerMatcher
Matches a variable declaration that has an initializer expression
-that matches the given matcher.
-
-Example matches x (matcher = varDecl(hasInitializer(callExpr())))
-  bool y() { return true; }
-  bool x = y();
-
Matcher<VariableArrayType>hasSizeExprMatcher<Expr> InnerMatcher
Matches VariableArrayType nodes that have a specific size
-expression.
-
-Given
-  void f(int b) {
-    int a[b];
-  }
-variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to(
-  varDecl(hasName("b")))))))
-  matches "int a[b]"
-
Matcher<WhileStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
-a given body.
-
-Given
-  for (;;) {}
-hasBody(compoundStmt())
-  matches 'for (;;) {}'
-with compoundStmt()
-  matching '{}'
-
Matcher<WhileStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
-or conditional operator.
-
-Example matches true (matcher = hasCondition(boolLiteral(equals(true))))
-  if (true) {}
-
Matcher<internal::BindableMatcher<NestedNameSpecifierLoc>>locMatcher<NestedNameSpecifier> InnerMatcher
Matches NestedNameSpecifierLocs for which the given inner
-NestedNameSpecifier-matcher matches.
-
Matcher<internal::BindableMatcher<TypeLoc>>locMatcher<QualType> InnerMatcher
Matches TypeLocs for which the given inner
-QualType-matcher matches.
-
- -
- - - - + + + +AST Matcher Reference + + + + + + + + + +
+ +

AST Matcher Reference

+ +

This document shows all currently implemented matchers. The matchers are grouped +by category and node type they match. You can click on matcher names to show the +matcher's source documentation.

+ +

There are three different basic categories of matchers: +

+

+ +

Within each category the matchers are ordered by node type they match on. +Note that if a matcher can match multiple node types, it will it will appear +multiple times. This means that by searching for Matcher<Stmt> you can +find all matchers that can be used to match on Stmt nodes.

+ +

The exception to that rule are matchers that can match on any node. Those +are marked with a * and are listed in the beginning of each category.

+ +

Note that the categorization of matchers is a great help when you combine +them into matcher expressions. You will usually want to form matcher expressions +that read like english sentences by alternating between node matchers and +narrowing or traversal matchers, like this: +

+recordDecl(hasDescendant(
+    ifStmt(hasTrueExpression(
+        expr(hasDescendant(
+            ifStmt()))))))
+
+

+ + +

Node Matchers

+ + +

Node matchers are at the core of matcher expressions - they specify the type +of node that is expected. Every match expression starts with a node matcher, +which can then be further refined with a narrowing or traversal matcher. All +traversal matchers take node matchers as their arguments.

+ +

For convenience, all node matchers take an arbitrary number of arguments +and implicitly act as allOf matchers.

+ +

Node matchers are the only matchers that support the bind("id") call to +bind the matched node to the given string, to be later retrieved from the +match callback.

+ +

It is important to remember that the arguments to node matchers are +predicates on the same node, just with additional information about the type. +This is often useful to make matcher expression more readable by inlining bind +calls into redundant node matchers inside another node matcher: +

+// This binds the CXXRecordDecl to "id", as the decl() matcher will stay on
+// the same node.
+recordDecl(decl().bind("id"), hasName("::MyClass"))
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Return typeNameParameters
Matcher<CXXCtorInitializer>cxxCtorInitializerMatcher<CXXCtorInitializer>...
Matches constructor initializers.
+
+Examples matches i(42).
+  class C {
+    C() : i(42) {}
+    int i;
+  };
+
Matcher<Decl>accessSpecDeclMatcher<AccessSpecDecl>...
Matches C++ access specifier declarations.
+
+Given
+  class C {
+  public:
+    int a;
+  };
+accessSpecDecl()
+  matches 'public:'
+
Matcher<Decl>classTemplateDeclMatcher<ClassTemplateDecl>...
Matches C++ class template declarations.
+
+Example matches Z
+  template<class T> class Z {};
+
Matcher<Decl>classTemplateSpecializationDeclMatcher<ClassTemplateSpecializationDecl>...
Matches C++ class template specializations.
+
+Given
+  template<typename T> class A {};
+  template<> class A<double> {};
+  A<int> a;
+classTemplateSpecializationDecl()
+  matches the specializations A<int> and A<double>
+
Matcher<Decl>cxxConstructorDeclMatcher<CXXConstructorDecl>...
Matches C++ constructor declarations.
+
+Example matches Foo::Foo() and Foo::Foo(int)
+  class Foo {
+   public:
+    Foo();
+    Foo(int);
+    int DoSomething();
+  };
+
Matcher<Decl>cxxConversionDeclMatcher<CXXConversionDecl>...
Matches conversion operator declarations.
+
+Example matches the operator.
+  class X { operator int() const; };
+
Matcher<Decl>cxxDestructorDeclMatcher<CXXDestructorDecl>...
Matches explicit C++ destructor declarations.
+
+Example matches Foo::~Foo()
+  class Foo {
+   public:
+    virtual ~Foo();
+  };
+
Matcher<Decl>cxxMethodDeclMatcher<CXXMethodDecl>...
Matches method declarations.
+
+Example matches y
+  class X { void y(); };
+
Matcher<Decl>cxxRecordDeclMatcher<CXXRecordDecl>...
Matches C++ class declarations.
+
+Example matches X, Z
+  class X;
+  template<class T> class Z {};
+
Matcher<Decl>declMatcher<Decl>...
Matches declarations.
+
+Examples matches X, C, and the friend declaration inside C;
+  void X();
+  class C {
+    friend X;
+  };
+
Matcher<Decl>declaratorDeclMatcher<DeclaratorDecl>...
Matches declarator declarations (field, variable, function
+and non-type template parameter declarations).
+
+Given
+  class X { int y; };
+declaratorDecl()
+  matches int y.
+
Matcher<Decl>enumConstantDeclMatcher<EnumConstantDecl>...
Matches enum constants.
+
+Example matches A, B, C
+  enum X {
+    A, B, C
+  };
+
Matcher<Decl>enumDeclMatcher<EnumDecl>...
Matches enum declarations.
+
+Example matches X
+  enum X {
+    A, B, C
+  };
+
Matcher<Decl>fieldDeclMatcher<FieldDecl>...
Matches field declarations.
+
+Given
+  class X { int m; };
+fieldDecl()
+  matches 'm'.
+
Matcher<Decl>friendDeclMatcher<FriendDecl>...
Matches friend declarations.
+
+Given
+  class X { friend void foo(); };
+friendDecl()
+  matches 'friend void foo()'.
+
Matcher<Decl>functionDeclMatcher<FunctionDecl>...
Matches function declarations.
+
+Example matches f
+  void f();
+
Matcher<Decl>functionTemplateDeclMatcher<FunctionTemplateDecl>...
Matches C++ function template declarations.
+
+Example matches f
+  template<class T> void f(T t) {}
+
Matcher<Decl>linkageSpecDeclMatcher<LinkageSpecDecl>...
Matches a declaration of a linkage specification.
+
+Given
+  extern "C" {}
+linkageSpecDecl()
+  matches "extern "C" {}"
+
Matcher<Decl>namedDeclMatcher<NamedDecl>...
Matches a declaration of anything that could have a name.
+
+Example matches X, S, the anonymous union type, i, and U;
+  typedef int X;
+  struct S {
+    union {
+      int i;
+    } U;
+  };
+
Matcher<Decl>namespaceAliasDeclMatcher<NamespaceAliasDecl>...
Matches a declaration of a namespace alias.
+
+Given
+  namespace test {}
+  namespace alias = ::test;
+namespaceAliasDecl()
+  matches "namespace alias" but not "namespace test"
+
Matcher<Decl>namespaceDeclMatcher<NamespaceDecl>...
Matches a declaration of a namespace.
+
+Given
+  namespace {}
+  namespace test {}
+namespaceDecl()
+  matches "namespace {}" and "namespace test {}"
+
Matcher<Decl>nonTypeTemplateParmDeclMatcher<NonTypeTemplateParmDecl>...
Matches non-type template parameter declarations.
+
+Given
+  template <typename T, int N> struct C {};
+nonTypeTemplateParmDecl()
+  matches 'N', but not 'T'.
+
Matcher<Decl>objcInterfaceDeclMatcher<ObjCInterfaceDecl>...
Matches Objective-C interface declarations.
+
+Example matches Foo
+  @interface Foo
+  @end
+
Matcher<Decl>parmVarDeclMatcher<ParmVarDecl>...
Matches parameter variable declarations.
+
+Given
+  void f(int x);
+parmVarDecl()
+  matches int x.
+
Matcher<Decl>recordDeclMatcher<RecordDecl>...
Matches class, struct, and union declarations.
+
+Example matches X, Z, U, and S
+  class X;
+  template<class T> class Z {};
+  struct S {};
+  union U {};
+
Matcher<Decl>staticAssertDeclMatcher<StaticAssertDecl>...
Matches a C++ static_assert declaration.
+
+Example:
+  staticAssertExpr()
+matches
+  static_assert(sizeof(S) == sizeof(int))
+in
+  struct S {
+    int x;
+  };
+  static_assert(sizeof(S) == sizeof(int));
+
Matcher<Decl>templateTypeParmDeclMatcher<TemplateTypeParmDecl>...
Matches template type parameter declarations.
+
+Given
+  template <typename T, int N> struct C {};
+templateTypeParmDecl()
+  matches 'T', but not 'N'.
+
Matcher<Decl>translationUnitDeclMatcher<TranslationUnitDecl>...
Matches the top declaration context.
+
+Given
+  int X;
+  namespace NS {
+  int Y;
+  }  namespace NS
+decl(hasDeclContext(translationUnitDecl()))
+  matches "int X", but not "int Y".
+
Matcher<Decl>typedefDeclMatcher<TypedefDecl>...
Matches typedef declarations.
+
+Given
+  typedef int X;
+typedefDecl()
+  matches "typedef int X"
+
Matcher<Decl>unresolvedUsingTypenameDeclMatcher<UnresolvedUsingTypenameDecl>...
Matches unresolved using value declarations that involve the
+typename.
+
+Given
+  template <typename T>
+  struct Base { typedef T Foo; };
+
+  template<typename T>
+  struct S : private Base<T> {
+    using typename Base<T>::Foo;
+  };
+unresolvedUsingTypenameDecl()
+  matches using Base<T>::Foo 
Matcher<Decl>unresolvedUsingValueDeclMatcher<UnresolvedUsingValueDecl>...
Matches unresolved using value declarations.
+
+Given
+  template<typename X>
+  class C : private X {
+    using X::x;
+  };
+unresolvedUsingValueDecl()
+  matches using X::x 
Matcher<Decl>usingDeclMatcher<UsingDecl>...
Matches using declarations.
+
+Given
+  namespace X { int x; }
+  using X::x;
+usingDecl()
+  matches using X::x 
Matcher<Decl>usingDirectiveDeclMatcher<UsingDirectiveDecl>...
Matches using namespace declarations.
+
+Given
+  namespace X { int x; }
+  using namespace X;
+usingDirectiveDecl()
+  matches using namespace X 
Matcher<Decl>valueDeclMatcher<ValueDecl>...
Matches any value declaration.
+
+Example matches A, B, C and F
+  enum X { A, B, C };
+  void F();
+
Matcher<Decl>varDeclMatcher<VarDecl>...
Matches variable declarations.
+
+Note: this does not match declarations of member variables, which are
+"field" declarations in Clang parlance.
+
+Example matches a
+  int a;
+
Matcher<NestedNameSpecifierLoc>nestedNameSpecifierLocMatcher<NestedNameSpecifierLoc>...
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc.
+
Matcher<NestedNameSpecifier>nestedNameSpecifierMatcher<NestedNameSpecifier>...
Matches nested name specifiers.
+
+Given
+  namespace ns {
+    struct A { static void f(); };
+    void A::f() {}
+    void g() { A::f(); }
+  }
+  ns::A a;
+nestedNameSpecifier()
+  matches "ns::" and both "A::"
+
Matcher<QualType>qualTypeMatcher<QualType>...
Matches QualTypes in the clang AST.
+
Matcher<Stmt>arraySubscriptExprMatcher<ArraySubscriptExpr>...
Matches array subscript expressions.
+
+Given
+  int i = a[1];
+arraySubscriptExpr()
+  matches "a[1]"
+
Matcher<Stmt>asmStmtMatcher<AsmStmt>...
Matches asm statements.
+
+ int i = 100;
+  __asm("mov al, 2");
+asmStmt()
+  matches '__asm("mov al, 2")'
+
Matcher<Stmt>binaryOperatorMatcher<BinaryOperator>...
Matches binary operator expressions.
+
+Example matches a || b
+  !(a || b)
+
Matcher<Stmt>breakStmtMatcher<BreakStmt>...
Matches break statements.
+
+Given
+  while (true) { break; }
+breakStmt()
+  matches 'break'
+
Matcher<Stmt>cStyleCastExprMatcher<CStyleCastExpr>...
Matches a C-style cast expression.
+
+Example: Matches (int*) 2.2f in
+  int i = (int) 2.2f;
+
Matcher<Stmt>callExprMatcher<CallExpr>...
Matches call expressions.
+
+Example matches x.y() and y()
+  X x;
+  x.y();
+  y();
+
Matcher<Stmt>caseStmtMatcher<CaseStmt>...
Matches case statements inside switch statements.
+
+Given
+  switch(a) { case 42: break; default: break; }
+caseStmt()
+  matches 'case 42: break;'.
+
Matcher<Stmt>castExprMatcher<CastExpr>...
Matches any cast nodes of Clang's AST.
+
+Example: castExpr() matches each of the following:
+  (int) 3;
+  const_cast<Expr *>(SubExpr);
+  char c = 0;
+but does not match
+  int i = (0);
+  int k = 0;
+
Matcher<Stmt>characterLiteralMatcher<CharacterLiteral>...
Matches character literals (also matches wchar_t).
+
+Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
+though.
+
+Example matches 'a', L'a'
+  char ch = 'a'; wchar_t chw = L'a';
+
Matcher<Stmt>compoundLiteralExprMatcher<CompoundLiteralExpr>...
Matches compound (i.e. non-scalar) literals
+
+Example match: {1}, (1, 2)
+  int array[4] = {1}; vector int myvec = (vector int)(1, 2);
+
Matcher<Stmt>compoundStmtMatcher<CompoundStmt>...
Matches compound statements.
+
+Example matches '{}' and '{{}}'in 'for (;;) {{}}'
+  for (;;) {{}}
+
Matcher<Stmt>conditionalOperatorMatcher<ConditionalOperator>...
Matches conditional operator expressions.
+
+Example matches a ? b : c
+  (a ? b : c) + 42
+
Matcher<Stmt>continueStmtMatcher<ContinueStmt>...
Matches continue statements.
+
+Given
+  while (true) { continue; }
+continueStmt()
+  matches 'continue'
+
Matcher<Stmt>cudaKernelCallExprMatcher<CUDAKernelCallExpr>...
Matches CUDA kernel call expression.
+
+Example matches,
+  kernel<<<i,j>>>();
+
Matcher<Stmt>cxxBindTemporaryExprMatcher<CXXBindTemporaryExpr>...
Matches nodes where temporaries are created.
+
+Example matches FunctionTakesString(GetStringByValue())
+    (matcher = cxxBindTemporaryExpr())
+  FunctionTakesString(GetStringByValue());
+  FunctionTakesStringByPointer(GetStringPointer());
+
Matcher<Stmt>cxxBoolLiteralMatcher<CXXBoolLiteralExpr>...
Matches bool literals.
+
+Example matches true
+  true
+
Matcher<Stmt>cxxCatchStmtMatcher<CXXCatchStmt>...
Matches catch statements.
+
+  try {} catch(int i) {}
+cxxCatchStmt()
+  matches 'catch(int i)'
+
Matcher<Stmt>cxxConstCastExprMatcher<CXXConstCastExpr>...
Matches a const_cast expression.
+
+Example: Matches const_cast<int*>(&r) in
+  int n = 42;
+  const int &r(n);
+  int* p = const_cast<int*>(&r);
+
Matcher<Stmt>cxxConstructExprMatcher<CXXConstructExpr>...
Matches constructor call expressions (including implicit ones).
+
+Example matches string(ptr, n) and ptr within arguments of f
+    (matcher = cxxConstructExpr())
+  void f(const string &a, const string &b);
+  char *ptr;
+  int n;
+  f(string(ptr, n), ptr);
+
Matcher<Stmt>cxxDefaultArgExprMatcher<CXXDefaultArgExpr>...
Matches the value of a default argument at the call site.
+
+Example matches the CXXDefaultArgExpr placeholder inserted for the
+    default value of the second parameter in the call expression f(42)
+    (matcher = cxxDefaultArgExpr())
+  void f(int x, int y = 0);
+  f(42);
+
Matcher<Stmt>cxxDeleteExprMatcher<CXXDeleteExpr>...
Matches delete expressions.
+
+Given
+  delete X;
+cxxDeleteExpr()
+  matches 'delete X'.
+
Matcher<Stmt>cxxDynamicCastExprMatcher<CXXDynamicCastExpr>...
Matches a dynamic_cast expression.
+
+Example:
+  cxxDynamicCastExpr()
+matches
+  dynamic_cast<D*>(&b);
+in
+  struct B { virtual ~B() {} }; struct D : B {};
+  B b;
+  D* p = dynamic_cast<D*>(&b);
+
Matcher<Stmt>cxxForRangeStmtMatcher<CXXForRangeStmt>...
Matches range-based for statements.
+
+cxxForRangeStmt() matches 'for (auto a : i)'
+  int i[] =  {1, 2, 3}; for (auto a : i);
+  for(int j = 0; j < 5; ++j);
+
Matcher<Stmt>cxxFunctionalCastExprMatcher<CXXFunctionalCastExpr>...
Matches functional cast expressions
+
+Example: Matches Foo(bar);
+  Foo f = bar;
+  Foo g = (Foo) bar;
+  Foo h = Foo(bar);
+
Matcher<Stmt>cxxMemberCallExprMatcher<CXXMemberCallExpr>...
Matches member call expressions.
+
+Example matches x.y()
+  X x;
+  x.y();
+
Matcher<Stmt>cxxNewExprMatcher<CXXNewExpr>...
Matches new expressions.
+
+Given
+  new X;
+cxxNewExpr()
+  matches 'new X'.
+
Matcher<Stmt>cxxNullPtrLiteralExprMatcher<CXXNullPtrLiteralExpr>...
Matches nullptr literal.
+
Matcher<Stmt>cxxOperatorCallExprMatcher<CXXOperatorCallExpr>...
Matches overloaded operator calls.
+
+Note that if an operator isn't overloaded, it won't match. Instead, use
+binaryOperator matcher.
+Currently it does not match operators such as new delete.
+FIXME: figure out why these do not match?
+
+Example matches both operator<<((o << b), c) and operator<<(o, b)
+    (matcher = cxxOperatorCallExpr())
+  ostream &operator<< (ostream &out, int i) { };
+  ostream &o; int b = 1, c = 1;
+  o << b << c;
+
Matcher<Stmt>cxxReinterpretCastExprMatcher<CXXReinterpretCastExpr>...
Matches a reinterpret_cast expression.
+
+Either the source expression or the destination type can be matched
+using has(), but hasDestinationType() is more specific and can be
+more readable.
+
+Example matches reinterpret_cast<char*>(&p) in
+  void* p = reinterpret_cast<char*>(&p);
+
Matcher<Stmt>cxxStaticCastExprMatcher<CXXStaticCastExpr>...
Matches a C++ static_cast expression.
+
+hasDestinationType
+reinterpretCast
+
+Example:
+  cxxStaticCastExpr()
+matches
+  static_cast<long>(8)
+in
+  long eight(static_cast<long>(8));
+
Matcher<Stmt>cxxTemporaryObjectExprMatcher<CXXTemporaryObjectExpr>...
Matches functional cast expressions having N != 1 arguments
+
+Example: Matches Foo(bar, bar)
+  Foo h = Foo(bar, bar);
+
Matcher<Stmt>cxxThisExprMatcher<CXXThisExpr>...
Matches implicit and explicit this expressions.
+
+Example matches the implicit this expression in "return i".
+    (matcher = cxxThisExpr())
+struct foo {
+  int i;
+  int f() { return i; }
+};
+
Matcher<Stmt>cxxThrowExprMatcher<CXXThrowExpr>...
Matches throw expressions.
+
+  try { throw 5; } catch(int i) {}
+cxxThrowExpr()
+  matches 'throw 5'
+
Matcher<Stmt>cxxTryStmtMatcher<CXXTryStmt>...
Matches try statements.
+
+  try {} catch(int i) {}
+cxxTryStmt()
+  matches 'try {}'
+
Matcher<Stmt>cxxUnresolvedConstructExprMatcher<CXXUnresolvedConstructExpr>...
Matches unresolved constructor call expressions.
+
+Example matches T(t) in return statement of f
+    (matcher = cxxUnresolvedConstructExpr())
+  template <typename T>
+  void f(const T& t) { return T(t); }
+
Matcher<Stmt>declRefExprMatcher<DeclRefExpr>...
Matches expressions that refer to declarations.
+
+Example matches x in if (x)
+  bool x;
+  if (x) {}
+
Matcher<Stmt>declStmtMatcher<DeclStmt>...
Matches declaration statements.
+
+Given
+  int a;
+declStmt()
+  matches 'int a'.
+
Matcher<Stmt>defaultStmtMatcher<DefaultStmt>...
Matches default statements inside switch statements.
+
+Given
+  switch(a) { case 42: break; default: break; }
+defaultStmt()
+  matches 'default: break;'.
+
Matcher<Stmt>doStmtMatcher<DoStmt>...
Matches do statements.
+
+Given
+  do {} while (true);
+doStmt()
+  matches 'do {} while(true)'
+
Matcher<Stmt>explicitCastExprMatcher<ExplicitCastExpr>...
Matches explicit cast expressions.
+
+Matches any cast expression written in user code, whether it be a
+C-style cast, a functional-style cast, or a keyword cast.
+
+Does not match implicit conversions.
+
+Note: the name "explicitCast" is chosen to match Clang's terminology, as
+Clang uses the term "cast" to apply to implicit conversions as well as to
+actual cast expressions.
+
+hasDestinationType.
+
+Example: matches all five of the casts in
+  int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))
+but does not match the implicit conversion in
+  long ell = 42;
+
Matcher<Stmt>exprMatcher<Expr>...
Matches expressions.
+
+Example matches x()
+  void f() { x(); }
+
Matcher<Stmt>exprWithCleanupsMatcher<ExprWithCleanups>...
Matches expressions that introduce cleanups to be run at the end
+of the sub-expression's evaluation.
+
+Example matches std::string()
+  const std::string str = std::string();
+
Matcher<Stmt>floatLiteralMatcher<FloatingLiteral>...
Matches float literals of all sizes encodings, e.g.
+1.0, 1.0f, 1.0L and 1e10.
+
+Does not match implicit conversions such as
+  float a = 10;
+
Matcher<Stmt>forStmtMatcher<ForStmt>...
Matches for statements.
+
+Example matches 'for (;;) {}'
+  for (;;) {}
+  int i[] =  {1, 2, 3}; for (auto a : i);
+
Matcher<Stmt>gnuNullExprMatcher<GNUNullExpr>...
Matches GNU __null expression.
+
Matcher<Stmt>gotoStmtMatcher<GotoStmt>...
Matches goto statements.
+
+Given
+  goto FOO;
+  FOO: bar();
+gotoStmt()
+  matches 'goto FOO'
+
Matcher<Stmt>ifStmtMatcher<IfStmt>...
Matches if statements.
+
+Example matches 'if (x) {}'
+  if (x) {}
+
Matcher<Stmt>implicitCastExprMatcher<ImplicitCastExpr>...
Matches the implicit cast nodes of Clang's AST.
+
+This matches many different places, including function call return value
+eliding, as well as any type conversions.
+
Matcher<Stmt>initListExprMatcher<InitListExpr>...
Matches init list expressions.
+
+Given
+  int a[] = { 1, 2 };
+  struct B { int x, y; };
+  B b = { 5, 6 };
+initListExpr()
+  matches "{ 1, 2 }" and "{ 5, 6 }"
+
Matcher<Stmt>integerLiteralMatcher<IntegerLiteral>...
Matches integer literals of all sizes encodings, e.g.
+1, 1L, 0x1 and 1U.
+
+Does not match character-encoded integers such as L'a'.
+
Matcher<Stmt>labelStmtMatcher<LabelStmt>...
Matches label statements.
+
+Given
+  goto FOO;
+  FOO: bar();
+labelStmt()
+  matches 'FOO:'
+
Matcher<Stmt>lambdaExprMatcher<LambdaExpr>...
Matches lambda expressions.
+
+Example matches [&](){return 5;}
+  [&](){return 5;}
+
Matcher<Stmt>materializeTemporaryExprMatcher<MaterializeTemporaryExpr>...
Matches nodes where temporaries are materialized.
+
+Example: Given
+  struct T {void func()};
+  T f();
+  void g(T);
+materializeTemporaryExpr() matches 'f()' in these statements
+  T u(f());
+  g(f());
+but does not match
+  f();
+  f().func();
+
Matcher<Stmt>memberExprMatcher<MemberExpr>...
Matches member expressions.
+
+Given
+  class Y {
+    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+    int a; static int b;
+  };
+memberExpr()
+  matches this->x, x, y.x, a, this->b
+
Matcher<Stmt>nullStmtMatcher<NullStmt>...
Matches null statements.
+
+  foo();;
+nullStmt()
+  matches the second ';'
+
Matcher<Stmt>objcMessageExprMatcher<ObjCMessageExpr>...
Matches ObjectiveC Message invocation expressions.
+
+The innermost message send invokes the "alloc" class method on the
+NSString class, while the outermost message send invokes the
+"initWithString" instance method on the object returned from
+NSString's "alloc". This matcher should match both message sends.
+  [[NSString alloc] initWithString:@"Hello"]
+
Matcher<Stmt>returnStmtMatcher<ReturnStmt>...
Matches return statements.
+
+Given
+  return 1;
+returnStmt()
+  matches 'return 1'
+
Matcher<Stmt>stmtMatcher<Stmt>...
Matches statements.
+
+Given
+  { ++a; }
+stmt()
+  matches both the compound statement '{ ++a; }' and '++a'.
+
Matcher<Stmt>stringLiteralMatcher<StringLiteral>...
Matches string literals (also matches wide string literals).
+
+Example matches "abcd", L"abcd"
+  char *s = "abcd"; wchar_t *ws = L"abcd"
+
Matcher<Stmt>substNonTypeTemplateParmExprMatcher<SubstNonTypeTemplateParmExpr>...
Matches substitutions of non-type template parameters.
+
+Given
+  template <int N>
+  struct A { static const int n = N; };
+  struct B : public A<42> {};
+substNonTypeTemplateParmExpr()
+  matches "N" in the right-hand side of "static const int n = N;"
+
Matcher<Stmt>switchCaseMatcher<SwitchCase>...
Matches case and default statements inside switch statements.
+
+Given
+  switch(a) { case 42: break; default: break; }
+switchCase()
+  matches 'case 42: break;' and 'default: break;'.
+
Matcher<Stmt>switchStmtMatcher<SwitchStmt>...
Matches switch statements.
+
+Given
+  switch(a) { case 42: break; default: break; }
+switchStmt()
+  matches 'switch(a)'.
+
Matcher<Stmt>unaryExprOrTypeTraitExprMatcher<UnaryExprOrTypeTraitExpr>...
Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
+
+Given
+  Foo x = bar;
+  int y = sizeof(x) + alignof(x);
+unaryExprOrTypeTraitExpr()
+  matches sizeof(x) and alignof(x)
+
Matcher<Stmt>unaryOperatorMatcher<UnaryOperator>...
Matches unary operator expressions.
+
+Example matches !a
+  !a || b
+
Matcher<Stmt>userDefinedLiteralMatcher<UserDefinedLiteral>...
Matches user defined literal operator call.
+
+Example match: "foo"_suffix
+
Matcher<Stmt>whileStmtMatcher<WhileStmt>...
Matches while statements.
+
+Given
+  while (true) {}
+whileStmt()
+  matches 'while (true) {}'.
+
Matcher<TemplateArgument>templateArgumentMatcher<TemplateArgument>...
Matches template arguments.
+
+Given
+  template <typename T> struct C {};
+  C<int> c;
+templateArgument()
+  matches 'int' in C<int>.
+
Matcher<TypeLoc>typeLocMatcher<TypeLoc>...
Matches TypeLocs in the clang AST.
+
Matcher<Type>arrayTypeMatcher<ArrayType>...
Matches all kinds of arrays.
+
+Given
+  int a[] = { 2, 3 };
+  int b[4];
+  void f() { int c[a[0]]; }
+arrayType()
+  matches "int a[]", "int b[4]" and "int c[a[0]]";
+
Matcher<Type>atomicTypeMatcher<AtomicType>...
Matches atomic types.
+
+Given
+  _Atomic(int) i;
+atomicType()
+  matches "_Atomic(int) i"
+
Matcher<Type>autoTypeMatcher<AutoType>...
Matches types nodes representing C++11 auto types.
+
+Given:
+  auto n = 4;
+  int v[] = { 2, 3 }
+  for (auto i : v) { }
+autoType()
+  matches "auto n" and "auto i"
+
Matcher<Type>blockPointerTypeMatcher<BlockPointerType>...
Matches block pointer types, i.e. types syntactically represented as
+"void (^)(int)".
+
+The pointee is always required to be a FunctionType.
+
Matcher<Type>builtinTypeMatcher<BuiltinType>...
Matches builtin Types.
+
+Given
+  struct A {};
+  A a;
+  int b;
+  float c;
+  bool d;
+builtinType()
+  matches "int b", "float c" and "bool d"
+
Matcher<Type>complexTypeMatcher<ComplexType>...
Matches C99 complex types.
+
+Given
+  _Complex float f;
+complexType()
+  matches "_Complex float f"
+
Matcher<Type>constantArrayTypeMatcher<ConstantArrayType>...
Matches C arrays with a specified constant size.
+
+Given
+  void() {
+    int a[2];
+    int b[] = { 2, 3 };
+    int c[b[0]];
+  }
+constantArrayType()
+  matches "int a[2]"
+
Matcher<Type>decayedTypeMatcher<DecayedType>...
Matches decayed type
+Example matches i[] in declaration of f.
+    (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())))))
+Example matches i[1].
+    (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())))))
+  void f(int i[]) {
+    i[1] = 0;
+  }
+
Matcher<Type>dependentSizedArrayTypeMatcher<DependentSizedArrayType>...
Matches C++ arrays whose size is a value-dependent expression.
+
+Given
+  template<typename T, int Size>
+  class array {
+    T data[Size];
+  };
+dependentSizedArrayType
+  matches "T data[Size]"
+
Matcher<Type>elaboratedTypeMatcher<ElaboratedType>...
Matches types specified with an elaborated type keyword or with a
+qualified name.
+
+Given
+  namespace N {
+    namespace M {
+      class D {};
+    }
+  }
+  class C {};
+
+  class C c;
+  N::M::D d;
+
+elaboratedType() matches the type of the variable declarations of both
+c and d.
+
Matcher<Type>functionTypeMatcher<FunctionType>...
Matches FunctionType nodes.
+
+Given
+  int (*f)(int);
+  void g();
+functionType()
+  matches "int (*f)(int)" and the type of "g".
+
Matcher<Type>incompleteArrayTypeMatcher<IncompleteArrayType>...
Matches C arrays with unspecified size.
+
+Given
+  int a[] = { 2, 3 };
+  int b[42];
+  void f(int c[]) { int d[a[0]]; };
+incompleteArrayType()
+  matches "int a[]" and "int c[]"
+
Matcher<Type>injectedClassNameTypeMatcher<InjectedClassNameType>...
Matches injected class name types.
+
+Example matches S s, but not S<T> s.
+    (matcher = parmVarDecl(hasType(injectedClassNameType())))
+  template <typename T> struct S {
+    void f(S s);
+    void g(S<T> s);
+  };
+
Matcher<Type>lValueReferenceTypeMatcher<LValueReferenceType>...
Matches lvalue reference types.
+
+Given:
+  int *a;
+  int &b = *a;
+  int &&c = 1;
+  auto &d = b;
+  auto &&e = c;
+  auto &&f = 2;
+  int g = 5;
+
+lValueReferenceType() matches the types of b, d, and e. e is
+matched since the type is deduced as int& by reference collapsing rules.
+
Matcher<Type>memberPointerTypeMatcher<MemberPointerType>...
Matches member pointer types.
+Given
+  struct A { int i; }
+  A::* ptr = A::i;
+memberPointerType()
+  matches "A::* ptr"
+
Matcher<Type>objcObjectPointerTypeMatcher<ObjCObjectPointerType>...
Matches an Objective-C object pointer type, which is different from
+a pointer type, despite being syntactically similar.
+
+Given
+  int *a;
+
+  @interface Foo
+  @end
+  Foo *f;
+pointerType()
+  matches "Foo *f", but does not match "int *a".
+
Matcher<Type>parenTypeMatcher<ParenType>...
Matches ParenType nodes.
+
+Given
+  int (*ptr_to_array)[4];
+  int *array_of_ptrs[4];
+
+varDecl(hasType(pointsTo(parenType()))) matches ptr_to_array but not
+array_of_ptrs.
+
Matcher<Type>pointerTypeMatcher<PointerType>...
Matches pointer types, but does not match Objective-C object pointer
+types.
+
+Given
+  int *a;
+  int &b = *a;
+  int c = 5;
+
+  @interface Foo
+  @end
+  Foo *f;
+pointerType()
+  matches "int *a", but does not match "Foo *f".
+
Matcher<Type>rValueReferenceTypeMatcher<RValueReferenceType>...
Matches rvalue reference types.
+
+Given:
+  int *a;
+  int &b = *a;
+  int &&c = 1;
+  auto &d = b;
+  auto &&e = c;
+  auto &&f = 2;
+  int g = 5;
+
+rValueReferenceType() matches the types of c and f. e is not
+matched as it is deduced to int& by reference collapsing rules.
+
Matcher<Type>recordTypeMatcher<RecordType>...
Matches record types (e.g. structs, classes).
+
+Given
+  class C {};
+  struct S {};
+
+  C c;
+  S s;
+
+recordType() matches the type of the variable declarations of both c
+and s.
+
Matcher<Type>referenceTypeMatcher<ReferenceType>...
Matches both lvalue and rvalue reference types.
+
+Given
+  int *a;
+  int &b = *a;
+  int &&c = 1;
+  auto &d = b;
+  auto &&e = c;
+  auto &&f = 2;
+  int g = 5;
+
+referenceType() matches the types of b, c, d, e, and f.
+
Matcher<Type>substTemplateTypeParmTypeMatcher<SubstTemplateTypeParmType>...
Matches types that represent the result of substituting a type for a
+template type parameter.
+
+Given
+  template <typename T>
+  void F(T t) {
+    int i = 1 + t;
+  }
+
+substTemplateTypeParmType() matches the type of 't' but not '1'
+
Matcher<Type>templateSpecializationTypeMatcher<TemplateSpecializationType>...
Matches template specialization types.
+
+Given
+  template <typename T>
+  class C { };
+
+  template class C<int>;  A
+  C<char> var;            B
+
+templateSpecializationType() matches the type of the explicit
+instantiation in A and the type of the variable declaration in B.
+
Matcher<Type>templateTypeParmTypeMatcher<TemplateTypeParmType>...
Matches template type parameter types.
+
+Example matches T, but not int.
+    (matcher = templateTypeParmType())
+  template <typename T> void f(int i);
+
Matcher<Type>typeMatcher<Type>...
Matches Types in the clang AST.
+
Matcher<Type>typedefTypeMatcher<TypedefType>...
Matches typedef types.
+
+Given
+  typedef int X;
+typedefType()
+  matches "typedef int X"
+
Matcher<Type>unaryTransformTypeMatcher<UnaryTransformType>...
Matches types nodes representing unary type transformations.
+
+Given:
+  typedef __underlying_type(T) type;
+unaryTransformType()
+  matches "__underlying_type(T)"
+
Matcher<Type>variableArrayTypeMatcher<VariableArrayType>...
Matches C arrays with a specified size that is not an
+integer-constant-expression.
+
+Given
+  void f() {
+    int a[] = { 2, 3 }
+    int b[42];
+    int c[a[0]];
+  }
+variableArrayType()
+  matches "int c[a[0]]"
+
+ + +

Narrowing Matchers

+ + +

Narrowing matchers match certain attributes on the current node, thus +narrowing down the set of nodes of the current type to match on.

+ +

There are special logical narrowing matchers (allOf, anyOf, anything and unless) +which allow users to create more powerful match expressions.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Return typeNameParameters
Matcher<*>allOfMatcher<*>, ..., Matcher<*>
Matches if all given matchers match.
+
+Usable as: Any Matcher
+
Matcher<*>anyOfMatcher<*>, ..., Matcher<*>
Matches if any of the given matchers matches.
+
+Usable as: Any Matcher
+
Matcher<*>anything
Matches any node.
+
+Useful when another matcher requires a child matcher, but there's no
+additional constraint. This will often be used with an explicit conversion
+to an internal::Matcher<> type such as TypeMatcher.
+
+Example: DeclarationMatcher(anything()) matches all declarations, e.g.,
+"int* p" and "void f()" in
+  int* p;
+  void f();
+
+Usable as: Any Matcher
+
Matcher<*>unlessMatcher<*>
Matches if the provided matcher does not match.
+
+Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
+  class X {};
+  class Y {};
+
+Usable as: Any Matcher
+
Matcher<BinaryOperator>hasOperatorNamestd::string Name
Matches the operator Name of operator expressions (binary or
+unary).
+
+Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
+  !(a || b)
+
Matcher<CXXBoolLiteral>equalsValueT Value
Matches literals that are equal to the given value.
+
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
+  true
+
+Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
+           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
+
Matcher<CXXCatchStmt>isCatchAll
Matches a C++ catch statement that has a catch-all handler.
+
+Given
+  try {
+    ...
+  } catch (int) {
+    ...
+  } catch (...) {
+    ...
+  }
+endcode
+cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
+
Matcher<CXXConstructExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
+a specific number of arguments (including absent default arguments).
+
+Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
+  void f(int x, int y);
+  f(0, 0);
+
Matcher<CXXConstructExpr>isListInitialization
Matches a constructor call expression which uses list initialization.
+
Matcher<CXXConstructorDecl>isCopyConstructor
Matches constructor declarations that are copy constructors.
+
+Given
+  struct S {
+    S(); #1
+    S(const S &); #2
+    S(S &&); #3
+  };
+cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
+
Matcher<CXXConstructorDecl>isDefaultConstructor
Matches constructor declarations that are default constructors.
+
+Given
+  struct S {
+    S(); #1
+    S(const S &); #2
+    S(S &&); #3
+  };
+cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
+
Matcher<CXXConstructorDecl>isExplicit
Matches constructor and conversion declarations that are marked with
+the explicit keyword.
+
+Given
+  struct S {
+    S(int); #1
+    explicit S(double); #2
+    operator int(); #3
+    explicit operator bool(); #4
+  };
+cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+cxxConversionDecl(isExplicit()) will match #4, but not #3.
+
Matcher<CXXConstructorDecl>isMoveConstructor
Matches constructor declarations that are move constructors.
+
+Given
+  struct S {
+    S(); #1
+    S(const S &); #2
+    S(S &&); #3
+  };
+cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
+
Matcher<CXXConversionDecl>isExplicit
Matches constructor and conversion declarations that are marked with
+the explicit keyword.
+
+Given
+  struct S {
+    S(int); #1
+    explicit S(double); #2
+    operator int(); #3
+    explicit operator bool(); #4
+  };
+cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+cxxConversionDecl(isExplicit()) will match #4, but not #3.
+
Matcher<CXXCtorInitializer>isBaseInitializer
Matches a constructor initializer if it is initializing a base, as
+opposed to a member.
+
+Given
+  struct B {};
+  struct D : B {
+    int I;
+    D(int i) : I(i) {}
+  };
+  struct E : B {
+    E() : B() {}
+  };
+cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))
+  will match E(), but not match D(int).
+
Matcher<CXXCtorInitializer>isMemberInitializer
Matches a constructor initializer if it is initializing a member, as
+opposed to a base.
+
+Given
+  struct B {};
+  struct D : B {
+    int I;
+    D(int i) : I(i) {}
+  };
+  struct E : B {
+    E() : B() {}
+  };
+cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
+  will match D(int), but not match E().
+
Matcher<CXXCtorInitializer>isWritten
Matches a constructor initializer if it is explicitly written in
+code (as opposed to implicitly added by the compiler).
+
+Given
+  struct Foo {
+    Foo() { }
+    Foo(int) : foo_("A") { }
+    string foo_;
+  };
+cxxConstructorDecl(hasAnyConstructorInitializer(isWritten()))
+  will match Foo(int), but not Foo()
+
Matcher<CXXMethodDecl>isConst
Matches if the given method declaration is const.
+
+Given
+struct A {
+  void foo() const;
+  void bar();
+};
+
+cxxMethodDecl(isConst()) matches A::foo() but not A::bar()
+
Matcher<CXXMethodDecl>isFinal
Matches if the given method or class declaration is final.
+
+Given:
+  class A final {};
+
+  struct B {
+    virtual void f();
+  };
+
+  struct C : B {
+    void f() final;
+  };
+matches A and C::f, but not B, C, or B::f
+
Matcher<CXXMethodDecl>isOverride
Matches if the given method declaration overrides another method.
+
+Given
+  class A {
+   public:
+    virtual void x();
+  };
+  class B : public A {
+   public:
+    virtual void x();
+  };
+  matches B::x
+
Matcher<CXXMethodDecl>isPure
Matches if the given method declaration is pure.
+
+Given
+  class A {
+   public:
+    virtual void x() = 0;
+  };
+  matches A::x
+
Matcher<CXXMethodDecl>isVirtual
Matches if the given method declaration is virtual.
+
+Given
+  class A {
+   public:
+    virtual void x();
+  };
+  matches A::x
+
Matcher<CXXOperatorCallExpr>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.
+
+Matches overloaded operator names specified in strings without the
+"operator" prefix: e.g. "<<".
+
+Given:
+  class A { int operator*(); };
+  const A &operator<<(const A &a, const A &b);
+  A a;
+  a << a;   <-- This matches
+
+cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
+specified line and
+cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
+matches the declaration of A.
+
+Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
+
Matcher<CXXRecordDecl>isDerivedFromstd::string BaseName
Overloaded method as shortcut for isDerivedFrom(hasName(...)).
+
Matcher<CXXRecordDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
+static member variable template instantiations.
+
+Given
+  template<typename T> void A(T t) { }
+  template<> void A(int N) { }
+functionDecl(isExplicitTemplateSpecialization())
+  matches the specialization A<int>().
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<CXXRecordDecl>isFinal
Matches if the given method or class declaration is final.
+
+Given:
+  class A final {};
+
+  struct B {
+    virtual void f();
+  };
+
+  struct C : B {
+    void f() final;
+  };
+matches A and C::f, but not B, C, or B::f
+
Matcher<CXXRecordDecl>isSameOrDerivedFromstd::string BaseName
Overloaded method as shortcut for
+isSameOrDerivedFrom(hasName(...)).
+
Matcher<CXXRecordDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
+member variable template instantiations.
+
+Given
+  template <typename T> class X {}; class A {}; X<A> x;
+or
+  template <typename T> class X {}; class A {}; template class X<A>;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  matches the template instantiation of X<A>.
+
+But given
+  template <typename T>  class X {}; class A {};
+  template <> class X<A> {}; X<A> x;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  does not match, as X<A> is an explicit template specialization.
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<CallExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
+a specific number of arguments (including absent default arguments).
+
+Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
+  void f(int x, int y);
+  f(0, 0);
+
Matcher<CharacterLiteral>equalsValueT Value
Matches literals that are equal to the given value.
+
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
+  true
+
+Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
+           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
+
Matcher<ClassTemplateSpecializationDecl>templateArgumentCountIsunsigned N
Matches if the number of template arguments equals N.
+
+Given
+  template<typename T> struct C {};
+  C<int> c;
+classTemplateSpecializationDecl(templateArgumentCountIs(1))
+  matches C<int>.
+
Matcher<CompoundStmt>statementCountIsunsigned N
Checks that a compound statement contains a specific number of
+child statements.
+
+Example: Given
+  { for (;;) {} }
+compoundStmt(statementCountIs(0)))
+  matches '{}'
+  but does not match the outer compound statement.
+
Matcher<ConstantArrayType>hasSizeunsigned N
Matches ConstantArrayType nodes that have the specified size.
+
+Given
+  int a[42];
+  int b[2 * 21];
+  int c[41], d[43];
+constantArrayType(hasSize(42))
+  matches "int a[42]" and "int b[2 * 21]"
+
Matcher<DeclStmt>declCountIsunsigned N
Matches declaration statements that contain a specific number of
+declarations.
+
+Example: Given
+  int a, b;
+  int c;
+  int d = 2, e;
+declCountIs(2)
+  matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
+
Matcher<Decl>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
+
+Matches a node if it equals the node previously bound to ID.
+
+Given
+  class X { int a; int b; };
+cxxRecordDecl(
+    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
+    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
+  matches the class X, as a and b have the same type.
+
+Note that when multiple matches are involved via forEach* matchers,
+equalsBoundNodes acts as a filter.
+For example:
+compoundStmt(
+    forEachDescendant(varDecl().bind("d")),
+    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
+will trigger a match for each combination of variable declaration
+and reference to that variable declaration within a compound statement.
+
Matcher<Decl>hasAttrattr::Kind AttrKind
Matches declaration that has a given attribute.
+
+Given
+  __attribute__((device)) void f() { ... }
+decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of
+f. If the matcher is use from clang-query, attr::Kind parameter should be
+passed as a quoted string. e.g., hasAttr("attr::CUDADevice").
+
Matcher<Decl>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
+partially matching a given regex.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
+  #include "ASTMatcher.h"
+  class X {};
+ASTMatcher.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Decl>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
+
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
+  #include <Y.h>
+  class X {};
+Y.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Decl>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
+  #include <SystemHeader.h>
+  class X {};
+SystemHeader.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Decl>isImplicit
Matches a declaration that has been implicitly added
+by the compiler (eg. implicit defaultcopy constructors).
+
Matcher<Decl>isPrivate
Matches private C++ declarations.
+
+Given
+  class C {
+  public:    int a;
+  protected: int b;
+  private:   int c;
+  };
+fieldDecl(isPrivate())
+  matches 'int c;' 
+
Matcher<Decl>isProtected
Matches protected C++ declarations.
+
+Given
+  class C {
+  public:    int a;
+  protected: int b;
+  private:   int c;
+  };
+fieldDecl(isProtected())
+  matches 'int b;' 
+
Matcher<Decl>isPublic
Matches public C++ declarations.
+
+Given
+  class C {
+  public:    int a;
+  protected: int b;
+  private:   int c;
+  };
+fieldDecl(isPublic())
+  matches 'int a;' 
+
Matcher<FloatingLiteral>equalsValueT Value
Matches literals that are equal to the given value.
+
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
+  true
+
+Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
+           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
+
Matcher<FunctionDecl>hasOverloadedOperatorNameStringRef Name
Matches overloaded operator names.
+
+Matches overloaded operator names specified in strings without the
+"operator" prefix: e.g. "<<".
+
+Given:
+  class A { int operator*(); };
+  const A &operator<<(const A &a, const A &b);
+  A a;
+  a << a;   <-- This matches
+
+cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
+specified line and
+cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
+matches the declaration of A.
+
+Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
+
Matcher<FunctionDecl>isConstexpr
Matches constexpr variable and function declarations.
+
+Given:
+  constexpr int foo = 42;
+  constexpr int bar();
+varDecl(isConstexpr())
+  matches the declaration of foo.
+functionDecl(isConstexpr())
+  matches the declaration of bar.
+
Matcher<FunctionDecl>isDefinition
Matches if a declaration has a body attached.
+
+Example matches A, va, fa
+  class A {};
+  class B;  Doesn't match, as it has no body.
+  int va;
+  extern int vb;  Doesn't match, as it doesn't define the variable.
+  void fa() {}
+  void fb();  Doesn't match, as it has no body.
+
+Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
+
Matcher<FunctionDecl>isDeleted
Matches deleted function declarations.
+
+Given:
+  void Func();
+  void DeletedFunc() = delete;
+functionDecl(isDeleted())
+  matches the declaration of DeletedFunc, but not Func.
+
Matcher<FunctionDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
+static member variable template instantiations.
+
+Given
+  template<typename T> void A(T t) { }
+  template<> void A(int N) { }
+functionDecl(isExplicitTemplateSpecialization())
+  matches the specialization A<int>().
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<FunctionDecl>isExternC
Matches extern "C" function declarations.
+
+Given:
+  extern "C" void f() {}
+  extern "C" { void g() {} }
+  void h() {}
+functionDecl(isExternC())
+  matches the declaration of f and g, but not the declaration h
+
Matcher<FunctionDecl>isInline
Matches function and namespace declarations that are marked with
+the inline keyword.
+
+Given
+  inline void f();
+  void g();
+  namespace n {
+  inline namespace m {}
+  }
+functionDecl(isInline()) will match ::f().
+namespaceDecl(isInline()) will match n::m.
+
Matcher<FunctionDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
+member variable template instantiations.
+
+Given
+  template <typename T> class X {}; class A {}; X<A> x;
+or
+  template <typename T> class X {}; class A {}; template class X<A>;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  matches the template instantiation of X<A>.
+
+But given
+  template <typename T>  class X {}; class A {};
+  template <> class X<A> {}; X<A> x;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  does not match, as X<A> is an explicit template specialization.
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<FunctionDecl>isVariadic
Matches if a function declaration is variadic.
+
+Example matches f, but not g or h. The function i will not match, even when
+compiled in C mode.
+  void f(...);
+  void g(int);
+  template <typename... Ts> void h(Ts...);
+  void i();
+
Matcher<FunctionDecl>parameterCountIsunsigned N
Matches FunctionDecls that have a specific parameter count.
+
+Given
+  void f(int i) {}
+  void g(int i, int j) {}
+functionDecl(parameterCountIs(2))
+  matches g(int i, int j) {}
+
Matcher<IntegerLiteral>equalsValueT Value
Matches literals that are equal to the given value.
+
+Example matches true (matcher = cxxBoolLiteral(equals(true)))
+  true
+
+Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteral>,
+           Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
+
Matcher<MemberExpr>isArrow
Matches member expressions that are called with '->' as opposed
+to '.'.
+
+Member calls on the implicit this pointer match as called with '->'.
+
+Given
+  class Y {
+    void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+    int a;
+    static int b;
+  };
+memberExpr(isArrow())
+  matches this->x, x, y.x, a, this->b
+
Matcher<NamedDecl>hasNamestd::string Name
Matches NamedDecl nodes that have the specified name.
+
+Supports specifying enclosing namespaces or classes by prefixing the name
+with '<enclosing>::'.
+Does not match typedefs of an underlying type with the given name.
+
+Example matches X (Name == "X")
+  class X;
+
+Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
+  namespace a { namespace b { class X; } }
+
Matcher<NamedDecl>matchesNamestd::string RegExp
Matches NamedDecl nodes whose fully qualified names contain
+a substring matched by the given RegExp.
+
+Supports specifying enclosing namespaces or classes by
+prefixing the name with '<enclosing>::'.  Does not match typedefs
+of an underlying type with the given name.
+
+Example matches X (regexp == "::X")
+  class X;
+
+Example matches X (regexp is one of "::X", "^foo::.*X", among others)
+  namespace foo { namespace bar { class X; } }
+
Matcher<NamespaceDecl>isAnonymous
Matches anonymous namespace declarations.
+
+Given
+  namespace n {
+  namespace {} #1
+  }
+namespaceDecl(isAnonymous()) will match #1 but not ::n.
+
Matcher<NamespaceDecl>isInline
Matches function and namespace declarations that are marked with
+the inline keyword.
+
+Given
+  inline void f();
+  void g();
+  namespace n {
+  inline namespace m {}
+  }
+functionDecl(isInline()) will match ::f().
+namespaceDecl(isInline()) will match n::m.
+
Matcher<ObjCMessageExpr>argumentCountIsunsigned N
Checks that a call expression or a constructor call expression has
+a specific number of arguments (including absent default arguments).
+
+Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
+  void f(int x, int y);
+  f(0, 0);
+
Matcher<ObjCMessageExpr>hasKeywordSelector
Matches when the selector is a keyword selector
+
+objCMessageExpr(hasKeywordSelector()) matches the generated setFrame
+message expression in
+
+  UIWebView *webView = ...;
+  CGRect bodyFrame = webView.frame;
+  bodyFrame.size.height = self.bodyContentHeight;
+  webView.frame = bodyFrame;
+      ^---- matches here
+
Matcher<ObjCMessageExpr>hasNullSelector
Matches when the selector is the empty selector
+
+Matches only when the selector of the objCMessageExpr is NULL. This may
+represent an error condition in the tree!
+
Matcher<ObjCMessageExpr>hasSelectorstd::string BaseName
Matches when BaseName == Selector.getAsString()
+
+ matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:"));
+ matches the outer message expr in the code below, but NOT the message
+ invocation for self.bodyView.
+    [self.bodyView loadHTMLString:html baseURL:NULL];
+
Matcher<ObjCMessageExpr>hasUnarySelector
Matches when the selector is a Unary Selector
+
+ matcher = objCMessageExpr(matchesSelector(hasUnarySelector());
+ matches self.bodyView in the code below, but NOT the outer message
+ invocation of "loadHTMLString:baseURL:".
+    [self.bodyView loadHTMLString:html baseURL:NULL];
+
Matcher<ObjCMessageExpr>matchesSelectorstd::string RegExp
Matches ObjC selectors whose name contains
+a substring matched by the given RegExp.
+ matcher = objCMessageExpr(matchesSelector("loadHTMLStringmatches the outer message expr in the code below, but NOT the message
+ invocation for self.bodyView.
+    [self.bodyView loadHTMLString:html baseURL:NULL];
+
Matcher<ObjCMessageExpr>numSelectorArgsunsigned N
Matches when the selector has the specified number of arguments
+
+ matcher = objCMessageExpr(numSelectorArgs(0));
+ matches self.bodyView in the code below
+
+ matcher = objCMessageExpr(numSelectorArgs(2));
+ matches the invocation of "loadHTMLString:baseURL:" but not that
+ of self.bodyView
+    [self.bodyView loadHTMLString:html baseURL:NULL];
+
Matcher<QualType>asStringstd::string Name
Matches if the matched type is represented by the given string.
+
+Given
+  class Y { public: void x(); };
+  void z() { Y* y; y->x(); }
+cxxMemberCallExpr(on(hasType(asString("class Y *"))))
+  matches y->x()
+
Matcher<QualType>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
+
+Matches a node if it equals the node previously bound to ID.
+
+Given
+  class X { int a; int b; };
+cxxRecordDecl(
+    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
+    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
+  matches the class X, as a and b have the same type.
+
+Note that when multiple matches are involved via forEach* matchers,
+equalsBoundNodes acts as a filter.
+For example:
+compoundStmt(
+    forEachDescendant(varDecl().bind("d")),
+    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
+will trigger a match for each combination of variable declaration
+and reference to that variable declaration within a compound statement.
+
Matcher<QualType>hasLocalQualifiers
Matches QualType nodes that have local CV-qualifiers attached to
+the node, not hidden within a typedef.
+
+Given
+  typedef const int const_int;
+  const_int i;
+  int *const j;
+  int *volatile k;
+  int m;
+varDecl(hasType(hasLocalQualifiers())) matches only j and k.
+i is const-qualified but the qualifier is not local.
+
Matcher<QualType>isConstQualified
Matches QualType nodes that are const-qualified, i.e., that
+include "top-level" const.
+
+Given
+  void a(int);
+  void b(int const);
+  void c(const int);
+  void d(const int*);
+  void e(int const) {};
+functionDecl(hasAnyParameter(hasType(isConstQualified())))
+  matches "void b(int const)", "void c(const int)" and
+  "void e(int const) {}". It does not match d as there
+  is no top-level const on the parameter type "const int *".
+
Matcher<QualType>isInteger
Matches QualType nodes that are of integer type.
+
+Given
+  void a(int);
+  void b(long);
+  void c(double);
+functionDecl(hasAnyParameter(hasType(isInteger())))
+matches "a(int)", "b(long)", but not "c(double)".
+
Matcher<RecordDecl>isClass
Matches RecordDecl object that are spelled with "class."
+
+Example matches C, but not S or U.
+  struct S {};
+  class C {};
+  union U {};
+
Matcher<RecordDecl>isStruct
Matches RecordDecl object that are spelled with "struct."
+
+Example matches S, but not C or U.
+  struct S {};
+  class C {};
+  union U {};
+
Matcher<RecordDecl>isUnion
Matches RecordDecl object that are spelled with "union."
+
+Example matches U, but not C or S.
+  struct S {};
+  class C {};
+  union U {};
+
Matcher<Stmt>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
+
+Matches a node if it equals the node previously bound to ID.
+
+Given
+  class X { int a; int b; };
+cxxRecordDecl(
+    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
+    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
+  matches the class X, as a and b have the same type.
+
+Note that when multiple matches are involved via forEach* matchers,
+equalsBoundNodes acts as a filter.
+For example:
+compoundStmt(
+    forEachDescendant(varDecl().bind("d")),
+    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
+will trigger a match for each combination of variable declaration
+and reference to that variable declaration within a compound statement.
+
Matcher<Stmt>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
+partially matching a given regex.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
+  #include "ASTMatcher.h"
+  class X {};
+ASTMatcher.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Stmt>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
+
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
+  #include <Y.h>
+  class X {};
+Y.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Stmt>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
+  #include <SystemHeader.h>
+  class X {};
+SystemHeader.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<TagDecl>isDefinition
Matches if a declaration has a body attached.
+
+Example matches A, va, fa
+  class A {};
+  class B;  Doesn't match, as it has no body.
+  int va;
+  extern int vb;  Doesn't match, as it doesn't define the variable.
+  void fa() {}
+  void fb();  Doesn't match, as it has no body.
+
+Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
+
Matcher<TemplateArgument>equalsIntegralValuestd::string Value
Matches a TemplateArgument of integral type with a given value.
+
+Note that 'Value' is a string as the template argument's value is
+an arbitrary precision integer. 'Value' must be euqal to the canonical
+representation of that integral value in base 10.
+
+Given
+  template<int T> struct A {};
+  C<42> c;
+classTemplateSpecializationDecl(
+  hasAnyTemplateArgument(equalsIntegralValue("42")))
+  matches the implicit instantiation of C in C<42>.
+
Matcher<TemplateArgument>isIntegral
Matches a TemplateArgument that is an integral value.
+
+Given
+  template<int T> struct A {};
+  C<42> c;
+classTemplateSpecializationDecl(
+  hasAnyTemplateArgument(isIntegral()))
+  matches the implicit instantiation of C in C<42>
+  with isIntegral() matching 42.
+
Matcher<TemplateSpecializationType>templateArgumentCountIsunsigned N
Matches if the number of template arguments equals N.
+
+Given
+  template<typename T> struct C {};
+  C<int> c;
+classTemplateSpecializationDecl(templateArgumentCountIs(1))
+  matches C<int>.
+
Matcher<TypeLoc>isExpansionInFileMatchingstd::string RegExp
Matches AST nodes that were expanded within files whose name is
+partially matching a given regex.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
+  #include "ASTMatcher.h"
+  class X {};
+ASTMatcher.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<TypeLoc>isExpansionInMainFile
Matches AST nodes that were expanded within the main-file.
+
+Example matches X but not Y
+  (matcher = cxxRecordDecl(isExpansionInMainFile())
+  #include <Y.h>
+  class X {};
+Y.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<TypeLoc>isExpansionInSystemHeader
Matches AST nodes that were expanded within system-header-files.
+
+Example matches Y but not X
+    (matcher = cxxRecordDecl(isExpansionInSystemHeader())
+  #include <SystemHeader.h>
+  class X {};
+SystemHeader.h:
+  class Y {};
+
+Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
+
Matcher<Type>equalsBoundNodestd::string ID
Matches if a node equals a previously bound node.
+
+Matches a node if it equals the node previously bound to ID.
+
+Given
+  class X { int a; int b; };
+cxxRecordDecl(
+    has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
+    has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
+  matches the class X, as a and b have the same type.
+
+Note that when multiple matches are involved via forEach* matchers,
+equalsBoundNodes acts as a filter.
+For example:
+compoundStmt(
+    forEachDescendant(varDecl().bind("d")),
+    forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
+will trigger a match for each combination of variable declaration
+and reference to that variable declaration within a compound statement.
+
Matcher<Type>voidType
Matches type void.
+
+Given
+ struct S { void func(); };
+functionDecl(returns(voidType()))
+  matches "void func();"
+
Matcher<UnaryExprOrTypeTraitExpr>ofKindUnaryExprOrTypeTrait Kind
Matches unary expressions of a certain kind.
+
+Given
+  int x;
+  int s = sizeof(x) + alignof(x)
+unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
+  matches sizeof(x)
+
Matcher<UnaryOperator>hasOperatorNamestd::string Name
Matches the operator Name of operator expressions (binary or
+unary).
+
+Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
+  !(a || b)
+
Matcher<VarDecl>hasGlobalStorage
Matches a variable declaration that does not have local storage.
+
+Example matches y and z (matcher = varDecl(hasGlobalStorage())
+void f() {
+  int x;
+  static int y;
+}
+int z;
+
Matcher<VarDecl>hasLocalStorage
Matches a variable declaration that has function scope and is a
+non-static local variable.
+
+Example matches x (matcher = varDecl(hasLocalStorage())
+void f() {
+  int x;
+  static int y;
+}
+int z;
+
Matcher<VarDecl>isConstexpr
Matches constexpr variable and function declarations.
+
+Given:
+  constexpr int foo = 42;
+  constexpr int bar();
+varDecl(isConstexpr())
+  matches the declaration of foo.
+functionDecl(isConstexpr())
+  matches the declaration of bar.
+
Matcher<VarDecl>isDefinition
Matches if a declaration has a body attached.
+
+Example matches A, va, fa
+  class A {};
+  class B;  Doesn't match, as it has no body.
+  int va;
+  extern int vb;  Doesn't match, as it doesn't define the variable.
+  void fa() {}
+  void fb();  Doesn't match, as it has no body.
+
+Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
+
Matcher<VarDecl>isExceptionVariable
Matches a variable declaration that is an exception variable from
+a C++ catch block, or an Objective-C statement.
+
+Example matches x (matcher = varDecl(isExceptionVariable())
+void f(int y) {
+  try {
+  } catch (int x) {
+  }
+}
+
Matcher<VarDecl>isExplicitTemplateSpecialization
Matches explicit template specializations of function, class, or
+static member variable template instantiations.
+
+Given
+  template<typename T> void A(T t) { }
+  template<> void A(int N) { }
+functionDecl(isExplicitTemplateSpecialization())
+  matches the specialization A<int>().
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<VarDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
+member variable template instantiations.
+
+Given
+  template <typename T> class X {}; class A {}; X<A> x;
+or
+  template <typename T> class X {}; class A {}; template class X<A>;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  matches the template instantiation of X<A>.
+
+But given
+  template <typename T>  class X {}; class A {};
+  template <> class X<A> {}; X<A> x;
+cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
+  does not match, as X<A> is an explicit template specialization.
+
+Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
+
Matcher<internal::Matcher<Decl>>isInstantiated
Matches declarations that are template instantiations or are inside
+template instantiations.
+
+Given
+  template<typename T> void A(T t) { T i; }
+  A(0);
+  A(0U);
+functionDecl(isInstantiated())
+  matches 'A(int) {...};' and 'A(unsigned) {...}'.
+
Matcher<internal::Matcher<Stmt>>isInTemplateInstantiation
Matches statements inside of a template instantiation.
+
+Given
+  int j;
+  template<typename T> void A(T t) { T i; j += 42;}
+  A(0);
+  A(0U);
+declStmt(isInTemplateInstantiation())
+  matches 'int i;' and 'unsigned i'.
+unless(stmt(isInTemplateInstantiation()))
+  will NOT match j += 42; as it's shared between the template definition and
+  instantiation.
+
+ + +

AST Traversal Matchers

+ + +

Traversal matchers specify the relationship to other nodes that are +reachable from the current node.

+ +

Note that there are special traversal matchers (has, hasDescendant, forEach and +forEachDescendant) which work on all nodes and allow users to write more generic +match expressions.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Return typeNameParameters
Matcher<*>eachOfMatcher<*>, ..., Matcher<*>
Matches if any of the given matchers matches.
+
+Unlike anyOf, eachOf will generate a match result for each
+matching submatcher.
+
+For example, in:
+  class A { int a; int b; };
+The matcher:
+  cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
+                       has(fieldDecl(hasName("b")).bind("v"))))
+will generate two results binding "v", the first of which binds
+the field declaration of a, the second the field declaration of
+b.
+
+Usable as: Any Matcher
+
Matcher<*>forEachDescendantMatcher<*>
Matches AST nodes that have descendant AST nodes that match the
+provided matcher.
+
+Example matches X, A, B, C
+  (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))
+  class X {};  Matches X, because X::X is a class of name X inside X.
+  class A { class X {}; };
+  class B { class C { class X {}; }; };
+
+DescendantT must be an AST base type.
+
+As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
+each result that matches instead of only on the first one.
+
+Note: Recursively combined ForEachDescendant can cause many matches:
+  cxxRecordDecl(forEachDescendant(cxxRecordDecl(
+    forEachDescendant(cxxRecordDecl())
+  )))
+will match 10 times (plus injected class name matches) on:
+  class A { class B { class C { class D { class E {}; }; }; }; };
+
+Usable as: Any Matcher
+
Matcher<*>forEachMatcher<*>
Matches AST nodes that have child AST nodes that match the
+provided matcher.
+
+Example matches X, Y
+  (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
+  class X {};  Matches X, because X::X is a class of name X inside X.
+  class Y { class X {}; };
+  class Z { class Y { class X {}; }; };  Does not match Z.
+
+ChildT must be an AST base type.
+
+As opposed to 'has', 'forEach' will cause a match for each result that
+matches instead of only on the first one.
+
+Usable as: Any Matcher
+
Matcher<*>hasAncestorMatcher<*>
Matches AST nodes that have an ancestor that matches the provided
+matcher.
+
+Given
+void f() { if (true) { int x = 42; } }
+void g() { for (;;) { int x = 43; } }
+expr(integerLiteral(hasAncestor(ifStmt()))) matches 42, but not 43.
+
+Usable as: Any Matcher
+
Matcher<*>hasDescendantMatcher<*>
Matches AST nodes that have descendant AST nodes that match the
+provided matcher.
+
+Example matches X, Y, Z
+    (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))
+  class X {};  Matches X, because X::X is a class of name X inside X.
+  class Y { class X {}; };
+  class Z { class Y { class X {}; }; };
+
+DescendantT must be an AST base type.
+
+Usable as: Any Matcher
+
Matcher<*>hasMatcher<*>
Matches AST nodes that have child AST nodes that match the
+provided matcher.
+
+Example matches X, Y
+  (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))
+  class X {};  Matches X, because X::X is a class of name X inside X.
+  class Y { class X {}; };
+  class Z { class Y { class X {}; }; };  Does not match Z.
+
+ChildT must be an AST base type.
+
+Usable as: Any Matcher
+
Matcher<*>hasParentMatcher<*>
Matches AST nodes that have a parent that matches the provided
+matcher.
+
+Given
+void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }
+compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
+
+Usable as: Any Matcher
+
Matcher<ArraySubscriptExpr>hasBaseMatcher<Expr> InnerMatcher
Matches the base expression of an array subscript expression.
+
+Given
+  int i[5];
+  void f() { i[1] = 42; }
+arraySubscriptExpression(hasBase(implicitCastExpr(
+    hasSourceExpression(declRefExpr()))))
+  matches i[1] with the declRefExpr() matching i
+
Matcher<ArraySubscriptExpr>hasIndexMatcher<Expr> InnerMatcher
Matches the index expression of an array subscript expression.
+
+Given
+  int i[5];
+  void f() { i[1] = 42; }
+arraySubscriptExpression(hasIndex(integerLiteral()))
+  matches i[1] with the integerLiteral() matching 1
+
Matcher<ArrayTypeLoc>hasElementTypeLocMatcher<TypeLoc>
Matches arrays and C99 complex types that have a specific element
+type.
+
+Given
+  struct A {};
+  A a[7];
+  int b[7];
+arrayType(hasElementType(builtinType()))
+  matches "int b[7]"
+
+Usable as: Matcher<ArrayType>, Matcher<ComplexType>
+
Matcher<ArrayType>hasElementTypeMatcher<Type>
Matches arrays and C99 complex types that have a specific element
+type.
+
+Given
+  struct A {};
+  A a[7];
+  int b[7];
+arrayType(hasElementType(builtinType()))
+  matches "int b[7]"
+
+Usable as: Matcher<ArrayType>, Matcher<ComplexType>
+
Matcher<AtomicTypeLoc>hasValueTypeLocMatcher<TypeLoc>
Matches atomic types with a specific value type.
+
+Given
+  _Atomic(int) i;
+  _Atomic(float) f;
+atomicType(hasValueType(isInteger()))
+ matches "_Atomic(int) i"
+
+Usable as: Matcher<AtomicType>
+
Matcher<AtomicType>hasValueTypeMatcher<Type>
Matches atomic types with a specific value type.
+
+Given
+  _Atomic(int) i;
+  _Atomic(float) f;
+atomicType(hasValueType(isInteger()))
+ matches "_Atomic(int) i"
+
+Usable as: Matcher<AtomicType>
+
Matcher<AutoType>hasDeducedTypeMatcher<Type>
Matches AutoType nodes where the deduced type is a specific type.
+
+Note: There is no TypeLoc for the deduced type and thus no
+getDeducedLoc() matcher.
+
+Given
+  auto a = 1;
+  auto b = 2.0;
+autoType(hasDeducedType(isInteger()))
+  matches "auto a"
+
+Usable as: Matcher<AutoType>
+
Matcher<BinaryOperator>hasEitherOperandMatcher<Expr> InnerMatcher
Matches if either the left hand side or the right hand side of a
+binary operator matches.
+
Matcher<BinaryOperator>hasLHSMatcher<Expr> InnerMatcher
Matches the left hand side of binary operator expressions.
+
+Example matches a (matcher = binaryOperator(hasLHS()))
+  a || b
+
Matcher<BinaryOperator>hasRHSMatcher<Expr> InnerMatcher
Matches the right hand side of binary operator expressions.
+
+Example matches b (matcher = binaryOperator(hasRHS()))
+  a || b
+
Matcher<BlockPointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<BlockPointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<CXXConstructExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
+expression.
+
+Given
+  void x(int, int, int) { int y; x(1, y, 42); }
+callExpr(hasAnyArgument(declRefExpr()))
+  matches x(1, y, 42)
+with hasAnyArgument(...)
+  matching y
+
+FIXME: Currently this will ignore parentheses and implicit casts on
+the argument before applying the inner matcher. We'll want to remove
+this to allow for greater control by the user once ignoreImplicit()
+has been implemented.
+
Matcher<CXXConstructExpr>hasArgumentunsigned N, Matcher<Expr> InnerMatcher
Matches the n'th argument of a call expression or a constructor
+call expression.
+
+Example matches y in x(y)
+    (matcher = callExpr(hasArgument(0, declRefExpr())))
+  void x(int) { int y; x(y); }
+
Matcher<CXXConstructExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<CXXConstructorDecl>forEachConstructorInitializerMatcher<CXXCtorInitializer> InnerMatcher
Matches each constructor initializer in a constructor definition.
+
+Given
+  class A { A() : i(42), j(42) {} int i; int j; };
+cxxConstructorDecl(forEachConstructorInitializer(
+  forField(decl().bind("x"))
+))
+  will trigger two matches, binding for 'i' and 'j' respectively.
+
Matcher<CXXConstructorDecl>hasAnyConstructorInitializerMatcher<CXXCtorInitializer> InnerMatcher
Matches a constructor initializer.
+
+Given
+  struct Foo {
+    Foo() : foo_(1) { }
+    int foo_;
+  };
+cxxRecordDecl(has(cxxConstructorDecl(
+  hasAnyConstructorInitializer(anything())
+)))
+  record matches Foo, hasAnyConstructorInitializer matches foo_(1)
+
Matcher<CXXCtorInitializer>forFieldMatcher<FieldDecl> InnerMatcher
Matches the field declaration of a constructor initializer.
+
+Given
+  struct Foo {
+    Foo() : foo_(1) { }
+    int foo_;
+  };
+cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
+    forField(hasName("foo_"))))))
+  matches Foo
+with forField matching foo_
+
Matcher<CXXCtorInitializer>withInitializerMatcher<Expr> InnerMatcher
Matches the initializer expression of a constructor initializer.
+
+Given
+  struct Foo {
+    Foo() : foo_(1) { }
+    int foo_;
+  };
+cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
+    withInitializer(integerLiteral(equals(1)))))))
+  matches Foo
+with withInitializer matching (1)
+
Matcher<CXXForRangeStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
+a given body.
+
+Given
+  for (;;) {}
+hasBody(compoundStmt())
+  matches 'for (;;) {}'
+with compoundStmt()
+  matching '{}'
+
Matcher<CXXForRangeStmt>hasLoopVariableMatcher<VarDecl> InnerMatcher
Matches the initialization statement of a for loop.
+
+Example:
+    forStmt(hasLoopVariable(anything()))
+matches 'int x' in
+    for (int x : a) { }
+
Matcher<CXXForRangeStmt>hasRangeInitMatcher<Expr> InnerMatcher
Matches the range initialization statement of a for loop.
+
+Example:
+    forStmt(hasRangeInit(anything()))
+matches 'a' in
+    for (int x : a) { }
+
Matcher<CXXMemberCallExpr>onImplicitObjectArgumentMatcher<Expr> InnerMatcher
Matcher<CXXMemberCallExpr>onMatcher<Expr> InnerMatcher
Matches on the implicit object argument of a member call expression.
+
+Example matches y.x()
+  (matcher = cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))))
+  class Y { public: void x(); };
+  void z() { Y y; y.x(); }",
+
+FIXME: Overload to allow directly matching types?
+
Matcher<CXXMemberCallExpr>thisPointerTypeMatcher<Decl> InnerMatcher
Overloaded to match the type's declaration.
+
Matcher<CXXMemberCallExpr>thisPointerTypeMatcher<QualType> InnerMatcher
Matches if the expression's type either matches the specified
+matcher, or is a pointer to a type that matches the InnerMatcher.
+
Matcher<CXXMethodDecl>ofClassMatcher<CXXRecordDecl> InnerMatcher
Matches the class declaration that the given method declaration
+belongs to.
+
+FIXME: Generalize this for other kinds of declarations.
+FIXME: What other kind of declarations would we need to generalize
+this to?
+
+Example matches A() in the last line
+    (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl(
+        ofClass(hasName("A"))))))
+  class A {
+   public:
+    A();
+  };
+  A a = A();
+
Matcher<CXXRecordDecl>hasMethodMatcher<CXXMethodDecl> InnerMatcher
Matches the first method of a class or struct that satisfies InnerMatcher.
+
+Given:
+  class A { void func(); };
+  class B { void member(); };
+
+cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of
+A but not B.
+
Matcher<CXXRecordDecl>isDerivedFromMatcher<NamedDecl> Base
Matches C++ classes that are directly or indirectly derived from
+a class matching Base.
+
+Note that a class is not considered to be derived from itself.
+
+Example matches Y, Z, C (Base == hasName("X"))
+  class X;
+  class Y : public X {};  directly derived
+  class Z : public Y {};  indirectly derived
+  typedef X A;
+  typedef A B;
+  class C : public B {};  derived from a typedef of X
+
+In the following example, Bar matches isDerivedFrom(hasName("X")):
+  class Foo;
+  typedef Foo X;
+  class Bar : public Foo {};  derived from a type that X is a typedef of
+
Matcher<CXXRecordDecl>isSameOrDerivedFromMatcher<NamedDecl> Base
Similar to isDerivedFrom(), but also matches classes that directly
+match Base.
+
Matcher<CallExpr>calleeMatcher<Decl> InnerMatcher
Matches if the call expression's callee's declaration matches the
+given matcher.
+
+Example matches y.x() (matcher = callExpr(callee(
+                                   cxxMethodDecl(hasName("x")))))
+  class Y { public: void x(); };
+  void z() { Y y; y.x(); }
+
Matcher<CallExpr>calleeMatcher<Stmt> InnerMatcher
Matches if the call expression's callee expression matches.
+
+Given
+  class Y { void x() { this->x(); x(); Y y; y.x(); } };
+  void f() { f(); }
+callExpr(callee(expr()))
+  matches this->x(), x(), y.x(), f()
+with callee(...)
+  matching this->x, x, y.x, f respectively
+
+Note: Callee cannot take the more general internal::Matcher<Expr>
+because this introduces ambiguous overloads with calls to Callee taking a
+internal::Matcher<Decl>, as the matcher hierarchy is purely
+implemented in terms of implicit casts.
+
Matcher<CallExpr>hasAnyArgumentMatcher<Expr> InnerMatcher
Matches any argument of a call expression or a constructor call
+expression.
+
+Given
+  void x(int, int, int) { int y; x(1, y, 42); }
+callExpr(hasAnyArgument(declRefExpr()))
+  matches x(1, y, 42)
+with hasAnyArgument(...)
+  matching y
+
+FIXME: Currently this will ignore parentheses and implicit casts on
+the argument before applying the inner matcher. We'll want to remove
+this to allow for greater control by the user once ignoreImplicit()
+has been implemented.
+
Matcher<CallExpr>hasArgumentunsigned N, Matcher<Expr> InnerMatcher
Matches the n'th argument of a call expression or a constructor
+call expression.
+
+Example matches y in x(y)
+    (matcher = callExpr(hasArgument(0, declRefExpr())))
+  void x(int) { int y; x(y); }
+
Matcher<CallExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<CaseStmt>hasCaseConstantMatcher<Expr> InnerMatcher
If the given case statement does not use the GNU case range
+extension, matches the constant given in the statement.
+
+Given
+  switch (1) { case 1: case 1+1: case 3 ... 4: ; }
+caseStmt(hasCaseConstant(integerLiteral()))
+  matches "case 1:"
+
Matcher<CastExpr>hasSourceExpressionMatcher<Expr> InnerMatcher
Matches if the cast's source expression matches the given matcher.
+
+Example: matches "a string" (matcher =
+                                 hasSourceExpression(cxxConstructExpr()))
+class URL { URL(string); };
+URL url = "a string";
+
Matcher<ClassTemplateSpecializationDecl>hasAnyTemplateArgumentMatcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations that have at least one
+TemplateArgument matching the given InnerMatcher.
+
+Given
+  template<typename T> class A {};
+  template<> class A<double> {};
+  A<int> a;
+classTemplateSpecializationDecl(hasAnyTemplateArgument(
+    refersToType(asString("int"))))
+  matches the specialization A<int>
+
Matcher<ClassTemplateSpecializationDecl>hasTemplateArgumentunsigned N, Matcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations where the n'th TemplateArgument
+matches the given InnerMatcher.
+
+Given
+  template<typename T, typename U> class A {};
+  A<bool, int> b;
+  A<int, bool> c;
+classTemplateSpecializationDecl(hasTemplateArgument(
+    1, refersToType(asString("int"))))
+  matches the specialization A<bool, int>
+
Matcher<ComplexTypeLoc>hasElementTypeLocMatcher<TypeLoc>
Matches arrays and C99 complex types that have a specific element
+type.
+
+Given
+  struct A {};
+  A a[7];
+  int b[7];
+arrayType(hasElementType(builtinType()))
+  matches "int b[7]"
+
+Usable as: Matcher<ArrayType>, Matcher<ComplexType>
+
Matcher<ComplexType>hasElementTypeMatcher<Type>
Matches arrays and C99 complex types that have a specific element
+type.
+
+Given
+  struct A {};
+  A a[7];
+  int b[7];
+arrayType(hasElementType(builtinType()))
+  matches "int b[7]"
+
+Usable as: Matcher<ArrayType>, Matcher<ComplexType>
+
Matcher<CompoundStmt>hasAnySubstatementMatcher<Stmt> InnerMatcher
Matches compound statements where at least one substatement matches
+a given matcher.
+
+Given
+  { {}; 1+2; }
+hasAnySubstatement(compoundStmt())
+  matches '{ {}; 1+2; }'
+with compoundStmt()
+  matching '{}'
+
Matcher<ConditionalOperator>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
+or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
+  if (true) {}
+
Matcher<ConditionalOperator>hasFalseExpressionMatcher<Expr> InnerMatcher
Matches the false branch expression of a conditional operator.
+
+Example matches b
+  condition ? a : b
+
Matcher<ConditionalOperator>hasTrueExpressionMatcher<Expr> InnerMatcher
Matches the true branch expression of a conditional operator.
+
+Example matches a
+  condition ? a : b
+
Matcher<DecayedType>hasDecayedTypeMatcher<QualType> InnerType
Matches the decayed type, whos decayed type matches InnerMatcher
+
Matcher<DeclRefExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<DeclRefExpr>throughUsingDeclMatcher<UsingShadowDecl> InnerMatcher
Matches a DeclRefExpr that refers to a declaration through a
+specific using shadow declaration.
+
+Given
+  namespace a { void f() {} }
+  using a::f;
+  void g() {
+    f();     Matches this ..
+    a::f();  .. but not this.
+  }
+declRefExpr(throughUsingDecl(anything()))
+  matches f()
+
Matcher<DeclRefExpr>toMatcher<Decl> InnerMatcher
Matches a DeclRefExpr that refers to a declaration that matches the
+specified matcher.
+
+Example matches x in if(x)
+    (matcher = declRefExpr(to(varDecl(hasName("x")))))
+  bool x;
+  if (x) {}
+
Matcher<DeclStmt>containsDeclarationunsigned N, Matcher<Decl> InnerMatcher
Matches the n'th declaration of a declaration statement.
+
+Note that this does not work for global declarations because the AST
+breaks up multiple-declaration DeclStmt's into multiple single-declaration
+DeclStmt's.
+Example: Given non-global declarations
+  int a, b = 0;
+  int c;
+  int d = 2, e;
+declStmt(containsDeclaration(
+      0, varDecl(hasInitializer(anything()))))
+  matches only 'int d = 2, e;', and
+declStmt(containsDeclaration(1, varDecl()))
+  matches 'int a, b = 0' as well as 'int d = 2, e;'
+  but 'int c;' is not matched.
+
Matcher<DeclStmt>hasSingleDeclMatcher<Decl> InnerMatcher
Matches the Decl of a DeclStmt which has a single declaration.
+
+Given
+  int a, b;
+  int c;
+declStmt(hasSingleDecl(anything()))
+  matches 'int c;' but not 'int a, b;'.
+
Matcher<DeclaratorDecl>hasTypeLocMatcher<TypeLoc> Inner
Matches if the type location of the declarator decl's type matches
+the inner matcher.
+
+Given
+  int x;
+declaratorDecl(hasTypeLoc(loc(asString("int"))))
+  matches int x
+
Matcher<Decl>hasDeclContextMatcher<Decl> InnerMatcher
Matches declarations whose declaration context, interpreted as a
+Decl, matches InnerMatcher.
+
+Given
+  namespace N {
+    namespace M {
+      class D {};
+    }
+  }
+
+cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
+declaration of class D.
+
Matcher<DoStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
+a given body.
+
+Given
+  for (;;) {}
+hasBody(compoundStmt())
+  matches 'for (;;) {}'
+with compoundStmt()
+  matching '{}'
+
Matcher<DoStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
+or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
+  if (true) {}
+
Matcher<ElaboratedType>hasQualifierMatcher<NestedNameSpecifier> InnerMatcher
Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+matches InnerMatcher if the qualifier exists.
+
+Given
+  namespace N {
+    namespace M {
+      class D {};
+    }
+  }
+  N::M::D d;
+
+elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
+matches the type of the variable declaration of d.
+
Matcher<ElaboratedType>namesTypeMatcher<QualType> InnerMatcher
Matches ElaboratedTypes whose named type matches InnerMatcher.
+
+Given
+  namespace N {
+    namespace M {
+      class D {};
+    }
+  }
+  N::M::D d;
+
+elaboratedType(namesType(recordType(
+hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
+declaration of d.
+
Matcher<EnumType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<ExplicitCastExpr>hasDestinationTypeMatcher<QualType> InnerMatcher
Matches casts whose destination type matches a given matcher.
+
+(Note: Clang's AST refers to other conversions as "casts" too, and calls
+actual casts "explicit" casts.)
+
Matcher<Expr>hasTypeMatcher<Decl> InnerMatcher
Overloaded to match the declaration of the expression's or value
+declaration's type.
+
+In case of a value declaration (for example a variable declaration),
+this resolves one layer of indirection. For example, in the value
+declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of
+X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the
+declaration of x.
+
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
+ class X {};
+ void y(X &x) { x; X z; }
+
+Usable as: Matcher<Expr>, Matcher<ValueDecl>
+
Matcher<Expr>hasTypeMatcher<QualType> InnerMatcher
Matches if the expression's or declaration's type matches a type
+matcher.
+
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
+ class X {};
+ void y(X &x) { x; X z; }
+
Matcher<Expr>ignoringImpCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after any implicit casts
+are stripped off.
+
+Parentheses and explicit casts are not discarded.
+Given
+  int arr[5];
+  int a = 0;
+  char b = 0;
+  const int c = a;
+  int *d = arr;
+  long e = (long) 0l;
+The matchers
+   varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
+   varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
+would match the declarations for a, b, c, and d, but not e.
+While
+   varDecl(hasInitializer(integerLiteral()))
+   varDecl(hasInitializer(declRefExpr()))
+only match the declarations for b, c, and d.
+
Matcher<Expr>ignoringParenCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after parentheses and
+casts are stripped off.
+
+Implicit and non-C Style casts are also discarded.
+Given
+  int a = 0;
+  char b = (0);
+  void* c = reinterpret_cast<char*>(0);
+  char d = char(0);
+The matcher
+   varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
+would match the declarations for a, b, c, and d.
+while
+   varDecl(hasInitializer(integerLiteral()))
+only match the declaration for a.
+
Matcher<Expr>ignoringParenImpCastsMatcher<Expr> InnerMatcher
Matches expressions that match InnerMatcher after implicit casts and
+parentheses are stripped off.
+
+Explicit casts are not discarded.
+Given
+  int arr[5];
+  int a = 0;
+  char b = (0);
+  const int c = a;
+  int *d = (arr);
+  long e = ((long) 0l);
+The matchers
+   varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
+   varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
+would match the declarations for a, b, c, and d, but not e.
+while
+   varDecl(hasInitializer(integerLiteral()))
+   varDecl(hasInitializer(declRefExpr()))
+would only match the declaration for a.
+
Matcher<ForStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
+a given body.
+
+Given
+  for (;;) {}
+hasBody(compoundStmt())
+  matches 'for (;;) {}'
+with compoundStmt()
+  matching '{}'
+
Matcher<ForStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
+or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
+  if (true) {}
+
Matcher<ForStmt>hasIncrementMatcher<Stmt> InnerMatcher
Matches the increment statement of a for loop.
+
+Example:
+    forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
+matches '++x' in
+    for (x; x < N; ++x) { }
+
Matcher<ForStmt>hasLoopInitMatcher<Stmt> InnerMatcher
Matches the initialization statement of a for loop.
+
+Example:
+    forStmt(hasLoopInit(declStmt()))
+matches 'int x = 0' in
+    for (int x = 0; x < N; ++x) { }
+
Matcher<FunctionDecl>hasAnyParameterMatcher<ParmVarDecl> InnerMatcher
Matches any parameter of a function declaration.
+
+Does not match the 'this' parameter of a method.
+
+Given
+  class X { void f(int x, int y, int z) {} };
+cxxMethodDecl(hasAnyParameter(hasName("y")))
+  matches f(int x, int y, int z) {}
+with hasAnyParameter(...)
+  matching int y
+
Matcher<FunctionDecl>hasParameterunsigned N, Matcher<ParmVarDecl> InnerMatcher
Matches the n'th parameter of a function declaration.
+
+Given
+  class X { void f(int x) {} };
+cxxMethodDecl(hasParameter(0, hasType(varDecl())))
+  matches f(int x) {}
+with hasParameter(...)
+  matching int x
+
Matcher<FunctionDecl>returnsMatcher<QualType> InnerMatcher
Matches the return type of a function declaration.
+
+Given:
+  class X { int f() { return 1; } };
+cxxMethodDecl(returns(asString("int")))
+  matches int f() { return 1; }
+
Matcher<IfStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
+or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
+  if (true) {}
+
Matcher<IfStmt>hasConditionVariableStatementMatcher<DeclStmt> InnerMatcher
Matches the condition variable statement in an if statement.
+
+Given
+  if (A* a = GetAPointer()) {}
+hasConditionVariableStatement(...)
+  matches 'A* a = GetAPointer()'.
+
Matcher<IfStmt>hasElseMatcher<Stmt> InnerMatcher
Matches the else-statement of an if statement.
+
+Examples matches the if statement
+  (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true)))))
+  if (false) false; else true;
+
Matcher<IfStmt>hasThenMatcher<Stmt> InnerMatcher
Matches the then-statement of an if statement.
+
+Examples matches the if statement
+  (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true)))))
+  if (false) true; else false;
+
Matcher<ImplicitCastExpr>hasImplicitDestinationTypeMatcher<QualType> InnerMatcher
Matches implicit casts whose destination type matches a given
+matcher.
+
+FIXME: Unit test this matcher
+
Matcher<InjectedClassNameType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<LabelStmt>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<MemberExpr>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<MemberExpr>hasObjectExpressionMatcher<Expr> InnerMatcher
Matches a member expression where the object expression is
+matched by a given matcher.
+
+Given
+  struct X { int m; };
+  void f(X x) { x.m; m; }
+memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))))
+  matches "x.m" and "m"
+with hasObjectExpression(...)
+  matching "x" and the implicit object expression of "m" which has type X*.
+
Matcher<MemberExpr>memberMatcher<ValueDecl> InnerMatcher
Matches a member expression where the member is matched by a
+given matcher.
+
+Given
+  struct { int first, second; } first, second;
+  int i(second.first);
+  int j(first.second);
+memberExpr(member(hasName("first")))
+  matches second.first
+  but not first.second (because the member name there is "second").
+
Matcher<MemberPointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<MemberPointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<NestedNameSpecifierLoc>hasPrefixMatcher<NestedNameSpecifierLoc> InnerMatcher
Matches on the prefix of a NestedNameSpecifierLoc.
+
+Given
+  struct A { struct B { struct C {}; }; };
+  A::B::C c;
+nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))
+  matches "A::"
+
Matcher<NestedNameSpecifierLoc>specifiesTypeLocMatcher<TypeLoc> InnerMatcher
Matches nested name specifier locs that specify a type matching the
+given TypeLoc.
+
+Given
+  struct A { struct B { struct C {}; }; };
+  A::B::C c;
+nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(
+  hasDeclaration(cxxRecordDecl(hasName("A")))))))
+  matches "A::"
+
Matcher<NestedNameSpecifier>hasPrefixMatcher<NestedNameSpecifier> InnerMatcher
Matches on the prefix of a NestedNameSpecifier.
+
+Given
+  struct A { struct B { struct C {}; }; };
+  A::B::C c;
+nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and
+  matches "A::"
+
Matcher<NestedNameSpecifier>specifiesNamespaceMatcher<NamespaceDecl> InnerMatcher
Matches nested name specifiers that specify a namespace matching the
+given namespace matcher.
+
+Given
+  namespace ns { struct A {}; }
+  ns::A a;
+nestedNameSpecifier(specifiesNamespace(hasName("ns")))
+  matches "ns::"
+
Matcher<NestedNameSpecifier>specifiesTypeMatcher<QualType> InnerMatcher
Matches nested name specifiers that specify a type matching the
+given QualType matcher without qualifiers.
+
+Given
+  struct A { struct B { struct C {}; }; };
+  A::B::C c;
+nestedNameSpecifier(specifiesType(
+  hasDeclaration(cxxRecordDecl(hasName("A")))
+))
+  matches "A::"
+
Matcher<ObjCMessageExpr>hasArgumentunsigned N, Matcher<Expr> InnerMatcher
Matches the n'th argument of a call expression or a constructor
+call expression.
+
+Example matches y in x(y)
+    (matcher = callExpr(hasArgument(0, declRefExpr())))
+  void x(int) { int y; x(y); }
+
Matcher<ObjCMessageExpr>hasReceiverTypeMatcher<QualType> InnerMatcher
Matches on the receiver of an ObjectiveC Message expression.
+
+Example
+matcher = objCMessageExpr(hasRecieverType(asString("UIWebView *")));
+matches the [webView ...] message invocation.
+  NSString *webViewJavaScript = ...
+  UIWebView *webView = ...
+  [webView stringByEvaluatingJavaScriptFromString:webViewJavascript];
+
Matcher<ParenType>innerTypeMatcher<Type>
Matches ParenType nodes where the inner type is a specific type.
+
+Given
+  int (*ptr_to_array)[4];
+  int (*ptr_to_func)(int);
+
+varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches
+ptr_to_func but not ptr_to_array.
+
+Usable as: Matcher<ParenType>
+
Matcher<PointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<PointerType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<QualType>hasCanonicalTypeMatcher<QualType> InnerMatcher
Matches QualTypes whose canonical type matches InnerMatcher.
+
+Given:
+  typedef int &int_ref;
+  int a;
+  int_ref b = a;
+
+varDecl(hasType(qualType(referenceType()))))) will not match the
+declaration of b but varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.
+
Matcher<QualType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<QualType>pointsToMatcher<Decl> InnerMatcher
Overloaded to match the pointee type's declaration.
+
Matcher<QualType>pointsToMatcher<QualType> InnerMatcher
Matches if the matched type is a pointer type and the pointee type
+matches the specified matcher.
+
+Example matches y->x()
+  (matcher = cxxMemberCallExpr(on(hasType(pointsTo
+     cxxRecordDecl(hasName("Y")))))))
+  class Y { public: void x(); };
+  void z() { Y *y; y->x(); }
+
Matcher<QualType>referencesMatcher<Decl> InnerMatcher
Overloaded to match the referenced type's declaration.
+
Matcher<QualType>referencesMatcher<QualType> InnerMatcher
Matches if the matched type is a reference type and the referenced
+type matches the specified matcher.
+
+Example matches X &x and const X &y
+    (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X"))))))
+  class X {
+    void a(X b) {
+      X &x = b;
+      const X &y = b;
+    }
+  };
+
Matcher<RecordType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<ReferenceTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<ReferenceType>pointeeMatcher<Type>
Narrows PointerType (and similar) matchers to those where the
+pointee matches a given matcher.
+
+Given
+  int *a;
+  int const *b;
+  float const *f;
+pointerType(pointee(isConstQualified(), isInteger()))
+  matches "int const *b"
+
+Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
+  Matcher<PointerType>, Matcher<ReferenceType>
+
Matcher<Stmt>alignOfExprMatcher<UnaryExprOrTypeTraitExpr> InnerMatcher
Same as unaryExprOrTypeTraitExpr, but only matching
+alignof.
+
Matcher<Stmt>sizeOfExprMatcher<UnaryExprOrTypeTraitExpr> InnerMatcher
Same as unaryExprOrTypeTraitExpr, but only matching
+sizeof.
+
Matcher<SwitchStmt>forEachSwitchCaseMatcher<SwitchCase> InnerMatcher
Matches each case or default statement belonging to the given switch
+statement. This matcher may produce multiple matches.
+
+Given
+  switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } }
+switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s")
+  matches four times, with "c" binding each of "case 1:", "case 2:",
+"case 3:" and "case 4:", and "s" respectively binding "switch (1)",
+"switch (1)", "switch (2)" and "switch (2)".
+
Matcher<TagType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<TemplateArgument>isExprMatcher<Expr> InnerMatcher
Matches a sugar TemplateArgument that refers to a certain expression.
+
+Given
+  template<typename T> struct A {};
+  struct B { B* next; };
+  A<&B::next> a;
+templateSpecializationType(hasAnyTemplateArgument(
+  isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))
+  matches the specialization A<&B::next> with fieldDecl(...) matching
+    B::next
+
Matcher<TemplateArgument>refersToDeclarationMatcher<Decl> InnerMatcher
Matches a canonical TemplateArgument that refers to a certain
+declaration.
+
+Given
+  template<typename T> struct A {};
+  struct B { B* next; };
+  A<&B::next> a;
+classTemplateSpecializationDecl(hasAnyTemplateArgument(
+    refersToDeclaration(fieldDecl(hasName("next"))))
+  matches the specialization A<&B::next> with fieldDecl(...) matching
+    B::next
+
Matcher<TemplateArgument>refersToIntegralTypeMatcher<QualType> InnerMatcher
Matches a TemplateArgument that referes to an integral type.
+
+Given
+  template<int T> struct A {};
+  C<42> c;
+classTemplateSpecializationDecl(
+  hasAnyTemplateArgument(refersToIntegralType(asString("int"))))
+  matches the implicit instantiation of C in C<42>.
+
Matcher<TemplateArgument>refersToTypeMatcher<QualType> InnerMatcher
Matches a TemplateArgument that refers to a certain type.
+
+Given
+  struct X {};
+  template<typename T> struct A {};
+  A<X> a;
+classTemplateSpecializationDecl(hasAnyTemplateArgument(
+    refersToType(class(hasName("X")))))
+  matches the specialization A<X>
+
Matcher<TemplateSpecializationType>hasAnyTemplateArgumentMatcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations that have at least one
+TemplateArgument matching the given InnerMatcher.
+
+Given
+  template<typename T> class A {};
+  template<> class A<double> {};
+  A<int> a;
+classTemplateSpecializationDecl(hasAnyTemplateArgument(
+    refersToType(asString("int"))))
+  matches the specialization A<int>
+
Matcher<TemplateSpecializationType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<TemplateSpecializationType>hasTemplateArgumentunsigned N, Matcher<TemplateArgument> InnerMatcher
Matches classTemplateSpecializations where the n'th TemplateArgument
+matches the given InnerMatcher.
+
+Given
+  template<typename T, typename U> class A {};
+  A<bool, int> b;
+  A<int, bool> c;
+classTemplateSpecializationDecl(hasTemplateArgument(
+    1, refersToType(asString("int"))))
+  matches the specialization A<bool, int>
+
Matcher<TemplateTypeParmType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<T>findAllMatcher<T> Matcher
Matches if the node or any descendant matches.
+
+Generates results for each match.
+
+For example, in:
+  class A { class B {}; class C {}; };
+The matcher:
+  cxxRecordDecl(hasName("::A"),
+                findAll(cxxRecordDecl(isDefinition()).bind("m")))
+will generate results for A, B and C.
+
+Usable as: Any Matcher
+
Matcher<TypedefType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<UnaryExprOrTypeTraitExpr>hasArgumentOfTypeMatcher<QualType> InnerMatcher
Matches unary expressions that have a specific type of argument.
+
+Given
+  int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
+unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
+  matches sizeof(a) and alignof(c)
+
Matcher<UnaryOperator>hasUnaryOperandMatcher<Expr> InnerMatcher
Matches if the operand of a unary operator matches.
+
+Example matches true (matcher = hasUnaryOperand(
+                                  cxxBoolLiteral(equals(true))))
+  !true
+
Matcher<UnresolvedUsingType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
+matches the given matcher.
+
+The associated declaration is:
+- for type nodes, the declaration of the underlying type
+- for CallExpr, the declaration of the callee
+- for MemberExpr, the declaration of the referenced member
+- for CXXConstructExpr, the declaration of the constructor
+
+Also usable as Matcher<T> for any T supporting the getDecl() member
+function. e.g. various subtypes of clang::Type and various expressions.
+
+Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
+  Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
+  Matcher<LabelStmt>, Matcher<MemberExpr>, Matcher<QualType>,
+  Matcher<RecordType>, Matcher<TagType>,
+  Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>,
+  Matcher<TypedefType>, Matcher<UnresolvedUsingType>
+
Matcher<UsingDecl>hasAnyUsingShadowDeclMatcher<UsingShadowDecl> InnerMatcher
Matches any using shadow declaration.
+
+Given
+  namespace X { void b(); }
+  using X::b;
+usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
+  matches using X::b 
Matcher<UsingShadowDecl>hasTargetDeclMatcher<NamedDecl> InnerMatcher
Matches a using shadow declaration where the target declaration is
+matched by the given matcher.
+
+Given
+  namespace X { int a; void b(); }
+  using X::a;
+  using X::b;
+usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
+  matches using X::b but not using X::a 
Matcher<ValueDecl>hasTypeMatcher<Decl> InnerMatcher
Overloaded to match the declaration of the expression's or value
+declaration's type.
+
+In case of a value declaration (for example a variable declaration),
+this resolves one layer of indirection. For example, in the value
+declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of
+X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the
+declaration of x.
+
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
+ class X {};
+ void y(X &x) { x; X z; }
+
+Usable as: Matcher<Expr>, Matcher<ValueDecl>
+
Matcher<ValueDecl>hasTypeMatcher<QualType> InnerMatcher
Matches if the expression's or declaration's type matches a type
+matcher.
+
+Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
+            and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
+ class X {};
+ void y(X &x) { x; X z; }
+
Matcher<VarDecl>hasInitializerMatcher<Expr> InnerMatcher
Matches a variable declaration that has an initializer expression
+that matches the given matcher.
+
+Example matches x (matcher = varDecl(hasInitializer(callExpr())))
+  bool y() { return true; }
+  bool x = y();
+
Matcher<VariableArrayType>hasSizeExprMatcher<Expr> InnerMatcher
Matches VariableArrayType nodes that have a specific size
+expression.
+
+Given
+  void f(int b) {
+    int a[b];
+  }
+variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to(
+  varDecl(hasName("b")))))))
+  matches "int a[b]"
+
Matcher<WhileStmt>hasBodyMatcher<Stmt> InnerMatcher
Matches a 'for', 'while', or 'do while' statement that has
+a given body.
+
+Given
+  for (;;) {}
+hasBody(compoundStmt())
+  matches 'for (;;) {}'
+with compoundStmt()
+  matching '{}'
+
Matcher<WhileStmt>hasConditionMatcher<Expr> InnerMatcher
Matches the condition expression of an if statement, for loop,
+or conditional operator.
+
+Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
+  if (true) {}
+
Matcher<internal::BindableMatcher<NestedNameSpecifierLoc>>locMatcher<NestedNameSpecifier> InnerMatcher
Matches NestedNameSpecifierLocs for which the given inner
+NestedNameSpecifier-matcher matches.
+
Matcher<internal::BindableMatcher<TypeLoc>>locMatcher<QualType> InnerMatcher
Matches TypeLocs for which the given inner
+QualType-matcher matches.
+
+ +
+ + + + diff --git a/docs/Makefile b/docs/Makefile index a409cf6025b..a6c6e6c43be 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -30,6 +30,7 @@ $(PROJ_OBJ_DIR)/doxygen.cfg: doxygen.cfg.in -e 's/@enable_server_based_search@/NO/g' \ -e 's/@extra_search_mappings@//g' \ -e 's/@searchengine_url@//g' \ + -e 's/@DOT_IMAGE_FORMAT@/png/g' \ > $@ endif diff --git a/docs/MemorySanitizer.rst b/docs/MemorySanitizer.rst index 007e0866dec..f97355fd8c3 100644 --- a/docs/MemorySanitizer.rst +++ b/docs/MemorySanitizer.rst @@ -80,14 +80,11 @@ whether MemorySanitizer is enabled. :ref:`\_\_has\_feature ``__attribute__((no_sanitize_memory))`` ----------------------------------------------- -Some code should not be checked by MemorySanitizer. -One may use the function attribute -:ref:`no_sanitize_memory ` -to disable uninitialized checks in a particular function. -MemorySanitizer may still instrument such functions to avoid false positives. -This attribute may not be -supported by other compilers, so we suggest to use it together with -``__has_feature(memory_sanitizer)``. +Some code should not be checked by MemorySanitizer. One may use the function +attribute `no_sanitize_memory` to disable uninitialized checks in a particular +function. MemorySanitizer may still instrument such functions to avoid false +positives. This attribute may not be supported by other compilers, so we +suggest to use it together with ``__has_feature(memory_sanitizer)``. Blacklist --------- diff --git a/docs/Modules.rst b/docs/Modules.rst index 1f3d8989751..0ea3b5bb377 100644 --- a/docs/Modules.rst +++ b/docs/Modules.rst @@ -222,7 +222,7 @@ Modules are modeled as if each submodule were a separate translation unit, and a This behavior is currently only approximated when building a module with submodules. Entities within a submodule that has already been built are visible when building later submodules in that module. This can lead to fragile modules that depend on the build order used for the submodules of the module, and should not be relied upon. This behavior is subject to change. -As an example, in C, this implies that if two structs are defined in different submodules with the same name, those two types are distinct types (but may be *compatible* types if their definitions match. In C++, two structs defined with the same name in different submodules are the *same* type, and must be equivalent under C++'s One Definition Rule. +As an example, in C, this implies that if two structs are defined in different submodules with the same name, those two types are distinct types (but may be *compatible* types if their definitions match). In C++, two structs defined with the same name in different submodules are the *same* type, and must be equivalent under C++'s One Definition Rule. .. note:: diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index 77eb2e3db6f..779d45c2928 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -11,8 +11,8 @@ Written by the `LLVM Team `_ .. warning:: These are in-progress notes for the upcoming Clang 3.8 release. You may - prefer the `Clang 3.6 Release Notes - `_. + prefer the `Clang 3.7 Release Notes + `_. Introduction ============ @@ -54,7 +54,7 @@ Improvements to Clang's diagnostics Clang's diagnostics are constantly being improved to catch more issues, explain them more clearly, and provide more accurate source information -about them. The improvements since the 3.5 release include: +about them. The improvements since the 3.7 release include: - ... @@ -114,6 +114,51 @@ this section should help get you past the largest hurdles of upgrading. - ... +AST Matchers +------------ +The AST matcher functions were renamed to reflect the exact AST node names, +which is a breaking change to AST matching code. The following matchers were +affected: + +======================= ============================ +Previous Matcher Name New Matcher Name +======================= ============================ +recordDecl recordDecl and cxxRecordDecl +ctorInitializer cxxCtorInitializer +constructorDecl cxxConstructorDecl +destructorDecl cxxDestructorDecl +methodDecl cxxMethodDecl +conversionDecl cxxConversionDecl +memberCallExpr cxxMemberCallExpr +constructExpr cxxConstructExpr +unresolvedConstructExpr cxxUnresolvedConstructExpr +thisExpr cxxThisExpr +bindTemporaryExpr cxxBindTemporaryExpr +newExpr cxxNewExpr +deleteExpr cxxDeleteExpr +defaultArgExpr cxxDefaultArgExpr +operatorCallExpr cxxOperatorCallExpr +forRangeStmt cxxForRangeStmt +catchStmt cxxCatchStmt +tryStmt cxxTryStmt +throwExpr cxxThrowExpr +boolLiteral cxxBoolLiteral +nullPtrLiteralExpr cxxNullPtrLiteralExpr +reinterpretCastExpr cxxReinterpretCastExpr +staticCastExpr cxxStaticCastExpr +dynamicCastExpr cxxDynamicCastExpr +constCastExpr cxxConstCastExpr +functionalCastExpr cxxFunctionalCastExpr +temporaryObjectExpr cxxTemporaryObjectExpr +CUDAKernalCallExpr cudaKernelCallExpr +======================= ============================ + +recordDecl() previously matched AST nodes of type CXXRecordDecl, but now +matches AST nodes of type RecordDecl. If a CXXRecordDecl is required, use the +cxxRecordDecl() matcher instead. + +... + libclang -------- @@ -156,4 +201,4 @@ tree. If you have any questions or comments about Clang, please feel free to contact us via the `mailing -list `_. +list `_. diff --git a/docs/SanitizerCoverage.rst b/docs/SanitizerCoverage.rst index 65af6ffbf01..efcb49e6eb4 100644 --- a/docs/SanitizerCoverage.rst +++ b/docs/SanitizerCoverage.rst @@ -249,6 +249,33 @@ These counters may also be used for in-process coverage-guided fuzzers. See uintptr_t __sanitizer_update_counter_bitset_and_clear_counters(uint8_t *bitset); +Tracing data flow +================= + +An *experimental* feature to support data-flow-guided fuzzing. +With ``-fsanitize-coverage=trace-cmp`` the compiler will insert extra instrumentation +around comparison instructions and switch statements. +The fuzzer will need to define the following functions, +they will be called by the instrumented code. + +.. code-block:: c++ + + // Called before a comparison instruction. + // SizeAndType is a packed value containing + // - [63:32] the Size of the operands of comparison in bits + // - [31:0] the Type of comparison (one of ICMP_EQ, ... ICMP_SLE) + // Arg1 and Arg2 are arguments of the comparison. + void __sanitizer_cov_trace_cmp(uint64_t SizeAndType, uint64_t Arg1, uint64_t Arg2); + + // Called before a switch statement. + // Val is the switch operand. + // Cases[0] is the number of case constants. + // Cases[1] is the size of Val in bits. + // Cases[2:] are the case constants. + void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases); + +This interface is a subject to change. + Output directory ================ diff --git a/docs/ThreadSanitizer.rst b/docs/ThreadSanitizer.rst index d1aeaa8a58c..9a8b14040d3 100644 --- a/docs/ThreadSanitizer.rst +++ b/docs/ThreadSanitizer.rst @@ -86,25 +86,22 @@ this purpose. ``__attribute__((no_sanitize_thread))`` ----------------------------------------------- -Some code should not be instrumented by ThreadSanitizer. -One may use the function attribute -:ref:`no_sanitize_thread ` -to disable instrumentation of plain (non-atomic) loads/stores in a particular function. -ThreadSanitizer still instruments such functions to avoid false positives and -provide meaningful stack traces. -This attribute may not be -supported by other compilers, so we suggest to use it together with -``__has_feature(thread_sanitizer)``. +Some code should not be instrumented by ThreadSanitizer. One may use the +function attribute `no_sanitize_thread` to disable instrumentation of plain +(non-atomic) loads/stores in a particular function. ThreadSanitizer still +instruments such functions to avoid false positives and provide meaningful stack +traces. This attribute may not be supported by other compilers, so we suggest +to use it together with ``__has_feature(thread_sanitizer)``. Blacklist --------- ThreadSanitizer supports ``src`` and ``fun`` entity types in -:doc:`SanitizerSpecialCaseList`, that can be used to suppress data race reports in -the specified source files or functions. Unlike functions marked with -:ref:`no_sanitize_thread ` attribute, -blacklisted functions are not instrumented at all. This can lead to false positives -due to missed synchronization via atomic operations and missed stack frames in reports. +:doc:`SanitizerSpecialCaseList`, that can be used to suppress data race reports +in the specified source files or functions. Unlike functions marked with +`no_sanitize_thread` attribute, blacklisted functions are not instrumented at +all. This can lead to false positives due to missed synchronization via atomic +operations and missed stack frames in reports. Limitations ----------- diff --git a/docs/UsersManual.rst b/docs/UsersManual.rst index 53d7286e265..fdba358fb72 100644 --- a/docs/UsersManual.rst +++ b/docs/UsersManual.rst @@ -148,8 +148,8 @@ Formatting of Diagnostics Clang aims to produce beautiful diagnostics by default, particularly for new users that first come to Clang. However, different people have -different preferences, and sometimes Clang is driven by another program -that wants to parse simple and consistent output, not a person. For +different preferences, and sometimes Clang is driven not by a human, +but by a program that wants consistent and easily parsable output. For these cases, Clang provides a wide range of options to control the exact output format of the diagnostics that it generates. @@ -1065,6 +1065,16 @@ are listed below. order of memory stores the uninitialized value went through. This mode may use extra memory in programs that copy uninitialized memory a lot. + - ``-fsanitize-memory-use-after-dtor``: Enables use-after-destruction + detection in MemorySanitizer. After invocation of the destructor, + the object is considered no longer readable. Facilitates the + detection of use-after-destroy bugs. + + Setting the MSAN_OPTIONS=poison_in_dtor=1 enables the poisoning of + memory at runtime. Any subsequent access to the destroyed object + fails at runtime. This feature is still experimental, but this + environment variable must be set to 1 in order for the above flag + to have any effect. The ``-fsanitize=`` argument must also be provided when linking, in order to link to the appropriate runtime library. When using @@ -1345,15 +1355,18 @@ read by the backend. LLVM supports three different sample profile formats: 1. ASCII text. This is the easiest one to generate. The file is divided into sections, which correspond to each of the functions with profile - information. The format is described below. + information. The format is described below. It can also be generated from + the binary or gcov formats using the ``llvm-profdata`` tool. 2. Binary encoding. This uses a more efficient encoding that yields smaller - profile files, which may be useful when generating large profiles. It can be - generated from the text format using the ``llvm-profdata`` tool. + profile files. This is the format generated by the ``create_llvm_prof`` tool + in http://github.com/google/autofdo. 3. GCC encoding. This is based on the gcov format, which is accepted by GCC. It - is only interesting in environments where GCC and Clang co-exist. Similarly - to the binary encoding, it can be generated using the ``llvm-profdata`` tool. + is only interesting in environments where GCC and Clang co-exist. This + encoding is only generated by the ``create_gcov`` tool in + http://github.com/google/autofdo. It can be read by LLVM and + ``llvm-profdata``, but it cannot be generated by either. If you are using Linux Perf to generate sampling profiles, you can use the conversion tool ``create_llvm_prof`` described in the previous section. @@ -1367,19 +1380,32 @@ Sample Profile Text Format This section describes the ASCII text format for sampling profiles. It is, arguably, the easiest one to generate. If you are interested in generating any of the other two, consult the ``ProfileData`` library in in LLVM's source tree -(specifically, ``llvm/lib/ProfileData/SampleProfWriter.cpp``). +(specifically, ``include/llvm/ProfileData/SampleProfReader.h``). .. code-block:: console function1:total_samples:total_head_samples - offset1[.discriminator]: number_of_samples [fn1:num fn2:num ... ] - offset2[.discriminator]: number_of_samples [fn3:num fn4:num ... ] - ... - offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ] + offset1[.discriminator]: number_of_samples [fn1:num fn2:num ... ] + offset2[.discriminator]: number_of_samples [fn3:num fn4:num ... ] + ... + offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ] + offsetA[.discriminator]: fnA:num_of_total_samples + offsetA1[.discriminator]: number_of_samples [fn7:num fn8:num ... ] + offsetA1[.discriminator]: number_of_samples [fn9:num fn10:num ... ] + offsetB[.discriminator]: fnB:num_of_total_samples + offsetB1[.discriminator]: number_of_samples [fn11:num fn12:num ... ] + +This is a nested tree in which the identation represents the nesting level +of the inline stack. There are no blank lines in the file. And the spacing +within a single line is fixed. Additional spaces will result in an error +while reading the file. -The file may contain blank lines between sections and within a -section. However, the spacing within a single line is fixed. Additional -spaces will result in an error while reading the file. +Any line starting with the '#' character is completely ignored. + +Inlined calls are represented with indentation. The Inline stack is a +stack of source locations in which the top of the stack represents the +leaf function, and the bottom of the stack represents the actual +symbol to which the instruction belongs. Function names must be mangled in order for the profile loader to match them in the current translation unit. The two numbers in the @@ -1388,6 +1414,14 @@ function (first number), and the total number of samples accumulated in the prologue of the function (second number). This head sample count provides an indicator of how frequently the function is invoked. +There are two types of lines in the function body. + +- Sampled line represents the profile information of a source location. + ``offsetN[.discriminator]: number_of_samples [fn5:num fn6:num ... ]`` + +- Callsite line represents the profile information of an inlined callsite. + ``offsetA[.discriminator]: fnA:num_of_total_samples`` + Each sampled line may contain several items. Some are optional (marked below): @@ -1441,6 +1475,24 @@ d. [OPTIONAL] Potential call targets and samples. If present, this instruction that calls one of ``foo()``, ``bar()`` and ``baz()``, with ``baz()`` being the relatively more frequently called target. +As an example, consider a program with the call chain ``main -> foo -> bar``. +When built with optimizations enabled, the compiler may inline the +calls to ``bar`` and ``foo`` inside ``main``. The generated profile +could then be something like this: + +.. code-block:: console + + main:35504:0 + 1: _Z3foov:35504 + 2: _Z32bari:31977 + 1.1: 31977 + 2: 0 + +This profile indicates that there were a total of 35,504 samples +collected in main. All of those were at line 1 (the call to ``foo``). +Of those, 31,977 were spent inside the body of ``bar``. The last line +of the profile (``2: 0``) corresponds to line 2 inside ``main``. No +samples were collected there. Profiling with Instrumentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -1534,6 +1586,19 @@ with respect to profile creation and use. profile file, it reads from that file. If ``pathname`` is a directory name, it reads from ``pathname/default.profdata``. +Disabling Instrumentation +^^^^^^^^^^^^^^^^^^^^^^^^^ + +In certain situations, it may be useful to disable profile generation or use +for specific files in a build, without affecting the main compilation flags +used for the other files in the project. + +In these cases, you can use the flag ``-fno-profile-instr-generate`` (or +``-fno-profile-generate``) to disable profile generation, and +``-fno-profile-instr-use`` (or ``-fno-profile-use``) to disable profile use. + +Note that these flags should appear after the corresponding profile +flags to have an effect. Controlling Size of Debug Information ------------------------------------- @@ -1839,6 +1904,32 @@ Objective-C Language Features Objective-C++ Language Features =============================== +.. _openmp: + +OpenMP Features +=============== + +Clang supports all OpenMP 3.1 directives and clauses. In addition, some +features of OpenMP 4.0 are supported. For example, ``#pragma omp simd``, +``#pragma omp for simd``, ``#pragma omp parallel for simd`` directives, extended +set of atomic constructs, ``proc_bind`` clause for all parallel-based +directives, ``depend`` clause for ``#pragma omp task`` directive (except for +array sections), ``#pragma omp cancel`` and ``#pragma omp cancellation point`` +directives, and ``#pragma omp taskgroup`` directive. + +OpenMP support is disabled by default. Use :option:`-fopenmp=libomp` to enable +it. Support for OpenMP can be disabled with :option:`-fno-openmp`. + +Controlling implementation limits +--------------------------------- + +.. option:: -fopenmp-use-tls + + Controls code generation for OpenMP threadprivate variables. In presence of + this option all threadprivate variables are generated the same way as thread + local variables, using TLS support. If :option:`-fno-openmp-use-tls` + is provided or target does not support TLS, code generation for threadprivate + variables relies on OpenMP runtime library. .. _target_features: @@ -1992,7 +2083,7 @@ with a warning. For example: :: - clang-cl.exe: warning: argument unused during compilation: '/Zi' + clang-cl.exe: warning: argument unused during compilation: '/AI' To suppress warnings about unused arguments, use the ``-Qunused-arguments`` option. @@ -2021,14 +2112,21 @@ Execute ``clang-cl /?`` to see a list of supported options: /E Preprocess to stdout /fallback Fall back to cl.exe if clang-cl fails to compile /FA Output assembly code file during compilation - /Fa Output assembly code to this file during compilation + /Fa Output assembly code to this file during compilation (with /FA) /Fe Set output executable file or directory (ends in / or \) /FI Include file before parsing - /Fi Set preprocess output file name - /Fo Set output object file, or directory (ends in / or \) + /Fi Set preprocess output file name (with /P) + /Fo Set output object file, or directory (ends in / or \) (with /c) + /fp:except- + /fp:except + /fp:fast + /fp:precise + /fp:strict + /GA Assume thread-local variables are defined in the executable /GF- Disable string pooling /GR- Disable emission of RTTI data /GR Enable emission of RTTI data + /Gs Set stack probe size /Gw- Don't put each data item in its own section /Gw Put each data item in its own section /Gy- Don't put each function in its own section @@ -2049,11 +2147,13 @@ Execute ``clang-cl /?`` to see a list of supported options: /Oi Enable use of builtin functions /Os Optimize for size /Ot Optimize for speed - /Ox Maximum optimization /Oy- Disable frame pointer omission /Oy Enable frame pointer omission - /O Optimization level + /O Optimization level + /o Set output file or directory (ends in / or \) /P Preprocess to file + /Qvec- Disable the loop vectorization passes + /Qvec Enable the loop vectorization passes /showIncludes Print info about included files to stderr /TC Treat all source files as C /Tc Specify a C source file @@ -2066,6 +2166,8 @@ Execute ``clang-cl /?`` to see a list of supported options: /vmm Set the default most-general representation to multiple inheritance /vms Set the default most-general representation to single inheritance /vmv Set the default most-general representation to virtual inheritance + /volatile:iso Volatile loads and stores have standard semantics + /volatile:ms Volatile loads and stores have acquire and release semantics /W0 Disable all warnings /W1 Enable -Wall /W2 Enable -Wall @@ -2075,29 +2177,55 @@ Execute ``clang-cl /?`` to see a list of supported options: /WX- Do not treat warnings as errors /WX Treat warnings as errors /w Disable all warnings - /Zi Enable debug information + /Z7 Enable CodeView debug information in object files + /Zc:sizedDealloc- Disable C++14 sized global deallocation functions + /Zc:sizedDealloc Enable C++14 sized global deallocation functions + /Zc:strictStrings Treat string literals as const + /Zc:threadSafeInit- Disable thread-safe initialization of static variables + /Zc:threadSafeInit Enable thread-safe initialization of static variables + /Zc:trigraphs- Disable trigraphs (default) + /Zc:trigraphs Enable trigraphs + /Zi Alias for /Z7. Does not produce PDBs. + /Zl Don't mention any default libraries in the object file /Zp Set the default maximum struct packing alignment to 1 /Zp Specify the default maximum struct packing alignment /Zs Syntax-check only OPTIONS: - -### Print (but do not run) the commands to run for this compilation + -### Print (but do not run) the commands to run for this compilation + --analyze Run the static analyzer + -fansi-escape-codes Use ANSI escape codes for diagnostics + -fcolor-diagnostics Use colors in diagnostics + -fdiagnostics-parseable-fixits + Print fix-its in machine parseable form -fms-compatibility-version= - Dot-separated value representing the Microsoft compiler version - number to report in _MSC_VER (0 = don't define it (default)) - -fmsc-version= Microsoft compiler version number to report in _MSC_VER (0 = don't - define it (default)) + Dot-separated value representing the Microsoft compiler version + number to report in _MSC_VER (0 = don't define it (default)) + -fmsc-version= Microsoft compiler version number to report in _MSC_VER (0 = don't + define it (default)) + -fno-sanitize-coverage= + Disable specified features of coverage instrumentation for Sanitizers + -fno-sanitize-recover= + Disable recovery for specified sanitizers + -fno-sanitize-trap= + Disable trapping for specified sanitizers -fsanitize-blacklist= - Path to blacklist file for sanitizers - -fsanitize= Enable runtime instrumentation for bug detection: address (memory - errors) | thread (race detection) | undefined (miscellaneous - undefined behavior) - -mllvm Additional arguments to forward to LLVM's option processing - -Qunused-arguments Don't emit warning for unused driver arguments - --target= Generate code for the given target - -v Show commands to run and use verbose output - -W Enable the specified warning - -Xclang Pass to the clang compiler + Path to blacklist file for sanitizers + -fsanitize-coverage= + Specify the type of coverage instrumentation for Sanitizers + -fsanitize-recover= + Enable recovery for specified sanitizers + -fsanitize-trap= Enable trapping for specified sanitizers + -fsanitize= Turn on runtime checks for various forms of undefined or suspicious + behavior. See user manual for available checks + -gcodeview Generate CodeView debug information + -mllvm Additional arguments to forward to LLVM's option processing + -Qunused-arguments Don't emit warning for unused driver arguments + -R Enable the specified remark + --target= Generate code for the given target + -v Show commands to run and use verbose output + -W Enable the specified warning + -Xclang Pass to the clang compiler The /fallback Option ^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/analyzer/nullability.rst b/docs/analyzer/nullability.rst new file mode 100644 index 00000000000..93909d0f25d --- /dev/null +++ b/docs/analyzer/nullability.rst @@ -0,0 +1,92 @@ +============ +Nullability Checks +============ + +This document is a high level description of the nullablility checks. +These checks intended to use the annotations that is described in this +RFC: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-March/041798.html. + +Let's consider the following 2 categories: + +1) nullable +============ + +If a pointer 'p' has a nullable annotation and no explicit null check or assert, we should warn in the following cases: +- 'p' gets implicitly converted into nonnull pointer, for example, we are passing it to a function that takes a nonnull parameter. +- 'p' gets dereferenced + +Taking a branch on nullable pointers are the same like taking branch on null unspecified pointers. + +Explicit cast from nullable to nonnul:: + + __nullable id foo; + id bar = foo; + takesNonNull((_nonnull) bar); <— should not warn here (backward compatibility hack) + anotherTakesNonNull(bar); <— would be great to warn here, but not necessary(*) + +Because bar corresponds to the same symbol all the time it is not easy to implement the checker that way the cast only suppress the first call but not the second. For this reason in the first implementation after a contradictory cast happens, I will treat bar as nullable unspecified, this way all of the warnings will be suppressed. Treating the symbol as nullable unspecified also has an advantage that in case the takesNonNull function body is being inlined, the will be no warning, when the symbol is dereferenced. In case I have time after the initial version I might spend additional time to try to find a more sophisticated solution, in which we would produce the second warning (*). + +2) nonnull +============ + +- Dereferencing a nonnull, or sending message to it is ok. +- Converting nonnull to nullable is Ok. +- When there is an explicit cast from nonnull to nullable I will trust the cast (it is probable there for a reason, because this cast does not suppress any warnings or errors). +- But what should we do about null checks?:: + + __nonnull id takesNonnull(__nonnull id x) { + if (x == nil) { + // Defensive backward compatible code: + .... + return nil; <- Should the analyzer cover this piece of code? Should we require the cast (__nonnull)nil? + } + .... + } + +There are these directions: +- We can either take the branch; this way the branch is analyzed + - Should we not warn about any nullability issues in that branch? Probably not, it is ok to break the nullability postconditions when the nullability preconditions are violated. +- We can assume that these pointers are not null and we lose coverage with the analyzer. (This can be implemented either in constraint solver or in the checker itself.) + +Other Issues to keep in mind/take care of: +Messaging: +- Sending a message to a nullable pointer + - Even though the method might return a nonnull pointer, when it was sent to a nullable pointer the return type will be nullable. + - The result is nullable unless the receiver is known to be non null. +- Sending a message to a unspecified or nonnull pointer + - If the pointer is not assumed to be nil, we should be optimistic and use the nullability implied by the method. + - This will not happen automatically, since the AST will have null unspecified in this case. + +Inlining +============ + +A symbol may need to be treated differently inside an inlined body. For example, consider these conversions from nonnull to nullable in presence of inlining:: + + id obj = getNonnull(); + takesNullable(obj); + takesNonnull(obj); + + void takesNullable(nullable id obj) { + obj->ivar // we should assume obj is nullable and warn here + } + +With no special treatment, when the takesNullable is inlined the analyzer will not warn when the obj symbol is dereferenced. One solution for this is to reanalyze takesNullable as a top level function to get possible violations. The alternative method, deducing nullability information from the arguments after inlining is not robust enough (for example there might be more parameters with different nullability, but in the given path the two parameters might end up being the same symbol or there can be nested functions that take different view of the nullability of the same symbol). So the symbol will remain nonnull to avoid false positives but the functions that takes nullable parameters will be analyzed separately as well without inlining. + +Annotations on multi level pointers +============ + +Tracking multiple levels of annotations for pointers pointing to pointers would make the checker more complicated, because this way a vector of nullability qualifiers would be needed to be tracked for each symbol. This is not a big caveat, since once the top level pointer is dereferenced, the symvol for the inner pointer will have the nullability information. The lack of multi level annotation tracking only observable, when multiple levels of pointers are passed to a function which has a parameter with multiple levels of annotations. So for now the checker support the top level nullability qualifiers only.:: + + int * __nonnull * __nullable p; + int ** q = p; + takesStarNullableStarNullable(q); + +Implementation notes +============ + +What to track? +- The checker would track memory regions, and to each relevant region a qualifier information would be attached which is either nullable, nonnull or null unspecified (or contradicted to suppress warnings for a specific region). +- On a branch, where a nullable pointer is known to be non null, the checker treat it as a same way as a pointer annotated as nonnull. +- When there is an explicit cast from a null unspecified to either nonnull or nullable I will trust the cast. +- Unannotated pointers are treated the same way as pointers annotated with nullability unspecified qualifier, unless the region is wrapped in ASSUME_NONNULL macros. +- We might want to implement a callback for entry points to top level functions, where the pointer nullability assumptions would be made. diff --git a/docs/conf.py b/docs/conf.py index edb2d37c9c9..6d53d94aa31 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,7 @@ # serve to show the default. import sys, os +from datetime import date # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the @@ -41,7 +42,7 @@ # General information about the project. project = u'Clang' -copyright = u'2007-2015, The Clang Team' +copyright = u'2007-%d, The Clang Team' % date.today().year # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/doxygen.cfg.in b/docs/doxygen.cfg.in index fe5674a1668..f6c7cba6d39 100644 --- a/docs/doxygen.cfg.in +++ b/docs/doxygen.cfg.in @@ -2205,7 +2205,7 @@ DIRECTORY_GRAPH = YES # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. -DOT_IMAGE_FORMAT = png +DOT_IMAGE_FORMAT = @DOT_IMAGE_FORMAT@ # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. diff --git a/docs/tools/dump_ast_matchers.py b/docs/tools/dump_ast_matchers.py index 1e1fd3c9d69..5812f86e6f4 100644 --- a/docs/tools/dump_ast_matchers.py +++ b/docs/tools/dump_ast_matchers.py @@ -166,7 +166,7 @@ def act_on_decl(declaration, comment, allowed_types): \s*AST_POLYMORPHIC_SUPPORTED_TYPES\(([^)]*)\) \)\s*;\s*$""", declaration, flags=re.X) if m: - loc, name, n_results, results = m.groups()[0:4] + loc, name, results = m.groups()[0:3] result_types = [r.strip() for r in results.split(',')] comment_result_types = extract_result_types(comment) @@ -191,8 +191,8 @@ def act_on_decl(declaration, comment, allowed_types): \)\s*{\s*$""", declaration, flags=re.X) if m: - p, n, name, n_results, results = m.groups()[0:5] - args = m.groups()[5:] + p, n, name, results = m.groups()[0:4] + args = m.groups()[4:] result_types = [r.strip() for r in results.split(',')] if allowed_types and allowed_types != result_types: raise Exception('Inconsistent documentation for: %s' % name) diff --git a/docs/tools/dump_format_style.py b/docs/tools/dump_format_style.py index fdf03c6244c..54760529ea6 100755 --- a/docs/tools/dump_format_style.py +++ b/docs/tools/dump_format_style.py @@ -36,14 +36,35 @@ def __init__(self, name, type, comment): self.type = type self.comment = comment.strip() self.enum = None + self.nested_struct = None def __str__(self): s = '**%s** (``%s``)\n%s' % (self.name, self.type, doxygen2rst(indent(self.comment, 2))) if self.enum: s += indent('\n\nPossible values:\n\n%s\n' % self.enum, 2) + if self.nested_struct: + s += indent('\n\nNested configuration flags:\n\n%s\n' %self.nested_struct, + 2) return s +class NestedStruct: + def __init__(self, name, comment): + self.name = name + self.comment = comment.strip() + self.values = [] + + def __str__(self): + return '\n'.join(map(str, self.values)) + +class NestedField: + def __init__(self, name, comment): + self.name = name + self.comment = comment.strip() + + def __str__(self): + return '* ``%s`` %s' % (self.name, doxygen2rst(self.comment)) + class Enum: def __init__(self, name, comment): self.name = name @@ -65,18 +86,24 @@ def __str__(self): doxygen2rst(indent(self.comment, 2))) def clean_comment_line(line): - return line[3:].strip() + '\n' + if line == '/// \\code': + return '\n.. code-block:: c++\n\n' + if line == '/// \\endcode': + return '' + return line[4:] + '\n' def read_options(header): class State: - BeforeStruct, Finished, InStruct, InFieldComment, InEnum, \ - InEnumMemberComment = range(6) + BeforeStruct, Finished, InStruct, InNestedStruct, InNestedFieldComent, \ + InFieldComment, InEnum, InEnumMemberComment = range(8) state = State.BeforeStruct options = [] enums = {} + nested_structs = {} comment = '' enum = None + nested_struct = None for line in header: line = line.strip() @@ -97,13 +124,31 @@ class State: state = State.InEnum name = re.sub(r'enum\s+(\w+)\s*\{', '\\1', line) enum = Enum(name, comment) + elif line.startswith('struct'): + state = State.InNestedStruct + name = re.sub(r'struct\s+(\w+)\s*\{', '\\1', line) + nested_struct = NestedStruct(name, comment) elif line.endswith(';'): state = State.InStruct - field_type, field_name = re.match(r'([<>:\w]+)\s+(\w+);', line).groups() + field_type, field_name = re.match(r'([<>:\w(,\s)]+)\s+(\w+);', + line).groups() option = Option(str(field_name), str(field_type), comment) options.append(option) else: raise Exception('Invalid format, expected comment, field or enum') + elif state == State.InNestedStruct: + if line.startswith('///'): + state = State.InNestedFieldComent + comment = clean_comment_line(line) + elif line == '};': + state = State.InStruct + nested_structs[nested_struct.name] = nested_struct + elif state == State.InNestedFieldComent: + if line.startswith('///'): + comment += clean_comment_line(line) + else: + state = State.InNestedStruct + nested_struct.values.append(NestedField(line.replace(';', ''), comment)) elif state == State.InEnum: if line.startswith('///'): state = State.InEnumMemberComment @@ -124,9 +169,12 @@ class State: for option in options: if not option.type in ['bool', 'unsigned', 'int', 'std::string', - 'std::vector']: + 'std::vector', + 'std::vector']: if enums.has_key(option.type): option.enum = enums[option.type] + elif nested_structs.has_key(option.type): + option.nested_struct = nested_structs[option.type]; else: raise Exception('Unknown type: %s' % option.type) return options diff --git a/emscripten-version.txt b/emscripten-version.txt index ee57aeb690f..6b899e68da8 100644 --- a/emscripten-version.txt +++ b/emscripten-version.txt @@ -1,2 +1,2 @@ -"1.35.6" +"1.35.7" diff --git a/examples/analyzer-plugin/MainCallChecker.cpp b/examples/analyzer-plugin/MainCallChecker.cpp index a6f69fd175b..7f08760e3d4 100644 --- a/examples/analyzer-plugin/MainCallChecker.cpp +++ b/examples/analyzer-plugin/MainCallChecker.cpp @@ -30,7 +30,7 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const return; if (II->isStr("main")) { - ExplodedNode *N = C.generateSink(); + ExplodedNode *N = C.generateErrorNode(); if (!N) return; diff --git a/include/clang-c/CXCompilationDatabase.h b/include/clang-c/CXCompilationDatabase.h index 068a677a95e..9359abfebfe 100644 --- a/include/clang-c/CXCompilationDatabase.h +++ b/include/clang-c/CXCompilationDatabase.h @@ -125,6 +125,12 @@ clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); CINDEX_LINKAGE CXString clang_CompileCommand_getDirectory(CXCompileCommand); +/** + * \brief Get the filename associated with the CompileCommand. + */ +CINDEX_LINKAGE CXString +clang_CompileCommand_getFilename(CXCompileCommand); + /** * \brief Get the number of arguments in the compiler invocation. * diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 2794965d5b9..cd5eb4e4d22 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 30 +#define CINDEX_VERSION_MINOR 31 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -1573,7 +1573,7 @@ enum CXCursorKind { CXCursor_ObjCImplementationDecl = 18, /** \brief An Objective-C \@implementation for a category. */ CXCursor_ObjCCategoryImplDecl = 19, - /** \brief A typedef */ + /** \brief A typedef. */ CXCursor_TypedefDecl = 20, /** \brief A C++ class method. */ CXCursor_CXXMethod = 21, @@ -1982,7 +1982,11 @@ enum CXCursorKind { */ CXCursor_ObjCSelfExpr = 146, - CXCursor_LastExpr = CXCursor_ObjCSelfExpr, + /** \brief OpenMP 4.0 [2.4, Array Section]. + */ + CXCursor_OMPArraySectionExpr = 147, + + CXCursor_LastExpr = CXCursor_OMPArraySectionExpr, /* Statements */ CXCursor_FirstStmt = 200, @@ -2275,7 +2279,8 @@ enum CXCursorKind { CXCursor_CUDAGlobalAttr = 414, CXCursor_CUDAHostAttr = 415, CXCursor_CUDASharedAttr = 416, - CXCursor_LastAttr = CXCursor_CUDASharedAttr, + CXCursor_VisibilityAttr = 417, + CXCursor_LastAttr = CXCursor_VisibilityAttr, /* Preprocessing */ CXCursor_PreprocessingDirective = 500, @@ -3951,6 +3956,11 @@ CXFile clang_Module_getTopLevelHeader(CXTranslationUnit, * @{ */ +/** + * \brief Determine if a C++ field is declared 'mutable'. + */ +CINDEX_LINKAGE unsigned clang_CXXField_isMutable(CXCursor C); + /** * \brief Determine if a C++ member function or member function template is * pure virtual. diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index c67fa67ab6b..72bbb606df0 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -70,6 +70,7 @@ namespace clang { class VTableContextBase; namespace Builtin { class Context; } + enum BuiltinTemplateKind : int; namespace comments { class FullComment; @@ -176,8 +177,9 @@ class ASTContext : public RefCountedBase { ClassScopeSpecializationPattern; /// \brief Mapping from materialized temporaries with static storage duration - /// that appear in constant initializers to their evaluated values. - llvm::DenseMap + /// that appear in constant initializers to their evaluated values. These are + /// allocated in a std::map because their address must be stable. + llvm::DenseMap MaterializedTemporaryValues; /// \brief Representation of a "canonical" template template parameter that @@ -215,6 +217,9 @@ class ASTContext : public RefCountedBase { /// __builtin_va_list type. mutable TypedefDecl *BuiltinVaListDecl; + /// The typedef for the predefined \c __builtin_ms_va_list type. + mutable TypedefDecl *BuiltinMSVaListDecl; + /// \brief The typedef for the predefined \c id type. mutable TypedefDecl *ObjCIdDecl; @@ -242,6 +247,9 @@ class ASTContext : public RefCountedBase { /// The identifier 'NSCopying'. IdentifierInfo *NSCopyingName = nullptr; + /// The identifier '__make_integer_seq'. + mutable IdentifierInfo *MakeIntegerSeqName = nullptr; + QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTypeDecl; @@ -395,6 +403,7 @@ class ASTContext : public RefCountedBase { TranslationUnitDecl *TUDecl; mutable ExternCContextDecl *ExternCContext; + mutable BuiltinTemplateDecl *MakeIntegerSeqDecl; /// \brief The associated SourceManager object.a SourceManager &SourceMgr; @@ -433,6 +442,7 @@ class ASTContext : public RefCountedBase { friend class CXXRecordDecl; const TargetInfo *Target; + const TargetInfo *AuxTarget; clang::PrintingPolicy PrintingPolicy; public: @@ -446,10 +456,59 @@ class ASTContext : public RefCountedBase { /// \brief Contains parents of a node. typedef llvm::SmallVector ParentVector; - /// \brief Maps from a node to its parents. + /// \brief Maps from a node to its parents. This is used for nodes that have + /// pointer identity only, which are more common and we can save space by + /// only storing a unique pointer to them. typedef llvm::DenseMap> ParentMap; + llvm::PointerUnion4> ParentMapPointers; + + /// Parent map for nodes without pointer identity. We store a full + /// DynTypedNode for all keys. + typedef llvm::DenseMap< + ast_type_traits::DynTypedNode, + llvm::PointerUnion4> + ParentMapOtherNodes; + + /// Container for either a single DynTypedNode or for an ArrayRef to + /// DynTypedNode. For use with ParentMap. + class DynTypedNodeList { + typedef ast_type_traits::DynTypedNode DynTypedNode; + llvm::AlignedCharArrayUnion> Storage; + bool IsSingleNode; + + public: + DynTypedNodeList(const DynTypedNode &N) : IsSingleNode(true) { + new (Storage.buffer) DynTypedNode(N); + } + DynTypedNodeList(ArrayRef A) : IsSingleNode(false) { + new (Storage.buffer) ArrayRef(A); + } + + const ast_type_traits::DynTypedNode *begin() const { + if (!IsSingleNode) + return reinterpret_cast *>(Storage.buffer) + ->begin(); + return reinterpret_cast(Storage.buffer); + } + + const ast_type_traits::DynTypedNode *end() const { + if (!IsSingleNode) + return reinterpret_cast *>(Storage.buffer) + ->end(); + return reinterpret_cast(Storage.buffer) + 1; + } + + size_t size() const { return end() - begin(); } + bool empty() const { return begin() == end(); } + const DynTypedNode &operator[](size_t N) const { + assert(N < size() && "Out of bounds!"); + return *(begin() + N); + } + }; /// \brief Returns the parents of the given node. /// @@ -475,13 +534,11 @@ class ASTContext : public RefCountedBase { /// /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc, /// NestedNameSpecifier or NestedNameSpecifierLoc. - template - ArrayRef getParents(const NodeT &Node) { + template DynTypedNodeList getParents(const NodeT &Node) { return getParents(ast_type_traits::DynTypedNode::create(Node)); } - ArrayRef - getParents(const ast_type_traits::DynTypedNode &Node); + DynTypedNodeList getParents(const ast_type_traits::DynTypedNode &Node); const clang::PrintingPolicy &getPrintingPolicy() const { return PrintingPolicy; @@ -501,6 +558,9 @@ class ASTContext : public RefCountedBase { void *Allocate(size_t Size, unsigned Align = 8) const { return BumpAlloc.Allocate(Size, Align); } + template T *Allocate(size_t Num = 1) const { + return static_cast(Allocate(Num * sizeof(T), llvm::alignOf())); + } void Deallocate(void *Ptr) const { } /// Return the total amount of physical memory allocated for representing @@ -516,7 +576,8 @@ class ASTContext : public RefCountedBase { } const TargetInfo &getTargetInfo() const { return *Target; } - + const TargetInfo *getAuxTargetInfo() const { return AuxTarget; } + /// getIntTypeForBitwidth - /// sets integer QualTy according to specified details: /// bitwidth, signed/unsigned. @@ -812,6 +873,7 @@ class ASTContext : public RefCountedBase { TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } ExternCContextDecl *getExternCContextDecl() const; + BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; // Builtin Types. CanQualType VoidTy; @@ -835,9 +897,13 @@ class ASTContext : public RefCountedBase { CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; CanQualType ObjCBuiltinBoolTy; CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; - CanQualType OCLImage2dTy, OCLImage2dArrayTy; + CanQualType OCLImage2dTy, OCLImage2dArrayTy, OCLImage2dDepthTy; + CanQualType OCLImage2dArrayDepthTy, OCLImage2dMSAATy, OCLImage2dArrayMSAATy; + CanQualType OCLImage2dMSAADepthTy, OCLImage2dArrayMSAADepthTy; CanQualType OCLImage3dTy; - CanQualType OCLSamplerTy, OCLEventTy; + CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; + CanQualType OCLQueueTy, OCLNDRangeTy, OCLReserveIDTy; + CanQualType OMPArraySectionTy; // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. mutable QualType AutoDeductTy; // Deduction against 'auto'. @@ -881,6 +947,9 @@ class ASTContext : public RefCountedBase { void PrintStats() const; const SmallVectorImpl& getTypes() const { return Types; } + BuiltinTemplateDecl *buildBuiltinTemplateDecl(BuiltinTemplateKind BTK, + const IdentifierInfo *II) const; + /// \brief Create a new implicit TU-level CXXRecordDecl or RecordDecl /// declaration. RecordDecl *buildImplicitRecord(StringRef Name, @@ -955,6 +1024,9 @@ class ASTContext : public RefCountedBase { const FunctionType *adjustFunctionType(const FunctionType *Fn, FunctionType::ExtInfo EInfo); + /// Adjust the given function result type. + CanQualType getCanonicalFunctionResultType(QualType ResultType) const; + /// \brief Change the result type of a function type once it is deduced. void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType); @@ -1381,6 +1453,12 @@ class ASTContext : public RefCountedBase { return NSCopyingName; } + IdentifierInfo *getMakeIntegerSeqName() const { + if (!MakeIntegerSeqName) + MakeIntegerSeqName = &Idents.get("__make_integer_seq"); + return MakeIntegerSeqName; + } + /// \brief Retrieve the Objective-C "instancetype" type, if already known; /// otherwise, returns a NULL type; QualType getObjCInstanceType() { @@ -1571,6 +1649,15 @@ class ASTContext : public RefCountedBase { /// for some targets. Decl *getVaListTagDecl() const; + /// Retrieve the C type declaration corresponding to the predefined + /// \c __builtin_ms_va_list type. + TypedefDecl *getBuiltinMSVaListDecl() const; + + /// Retrieve the type of the \c __builtin_ms_va_list type. + QualType getBuiltinMSVaListType() const { + return getTypeDeclType(getBuiltinMSVaListDecl()); + } + /// \brief Return a type with additional \c const, \c volatile, or /// \c restrict qualifiers. QualType getCVRQualifiedType(QualType T, unsigned CVR) const { @@ -2306,6 +2393,14 @@ class ASTContext : public RefCountedBase { Expr *getDefaultArgExprForConstructor(const CXXConstructorDecl *CD, unsigned ParmIdx); + void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND); + + TypedefNameDecl *getTypedefNameForUnnamedTagDecl(const TagDecl *TD); + + void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD); + + DeclaratorDecl *getDeclaratorForUnnamedTagDecl(const TagDecl *TD); + void setManglingNumber(const NamedDecl *ND, unsigned Number); unsigned getManglingNumber(const NamedDecl *ND) const; @@ -2387,9 +2482,10 @@ class ASTContext : public RefCountedBase { /// This routine may only be invoked once for a given ASTContext object. /// It is normally invoked after ASTContext construction. /// - /// \param Target The target - void InitBuiltinTypes(const TargetInfo &Target); - + /// \param Target The target + void InitBuiltinTypes(const TargetInfo &Target, + const TargetInfo *AuxTarget = nullptr); + private: void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); @@ -2442,7 +2538,8 @@ class ASTContext : public RefCountedBase { void ReleaseDeclContextMaps(); void ReleaseParentMapEntries(); - std::unique_ptr AllParents; + std::unique_ptr PointerParents; + std::unique_ptr OtherParents; std::unique_ptr VTContext; diff --git a/include/clang/AST/ASTMutationListener.h b/include/clang/AST/ASTMutationListener.h index f4026e95264..3ff392de11a 100644 --- a/include/clang/AST/ASTMutationListener.h +++ b/include/clang/AST/ASTMutationListener.h @@ -92,18 +92,6 @@ class ASTMutationListener { virtual void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) {} - /// \brief A objc class extension redeclared or introduced a property. - /// - /// \param Prop the property in the class extension - /// - /// \param OrigProp the property from the original interface that was declared - /// or null if the property was introduced. - /// - /// \param ClassExt the class extension. - virtual void AddedObjCPropertyInClassExtension(const ObjCPropertyDecl *Prop, - const ObjCPropertyDecl *OrigProp, - const ObjCCategoryDecl *ClassExt) {} - /// \brief A declaration is marked used which was not previously marked used. /// /// \param D the declaration marked used diff --git a/include/clang/AST/ASTTypeTraits.h b/include/clang/AST/ASTTypeTraits.h index dc3c34f28d9..50ad9535a51 100644 --- a/include/clang/AST/ASTTypeTraits.h +++ b/include/clang/AST/ASTTypeTraits.h @@ -106,18 +106,25 @@ class ASTNodeKind { } }; + /// Check if the given ASTNodeKind identifies a type that offers pointer + /// identity. This is useful for the fast path in DynTypedNode. + bool hasPointerIdentity() const { + return KindId > NKI_LastKindWithoutPointerIdentity; + } + private: /// \brief Kind ids. /// /// Includes all possible base and derived kinds. enum NodeKindId { NKI_None, - NKI_CXXCtorInitializer, NKI_TemplateArgument, - NKI_NestedNameSpecifier, NKI_NestedNameSpecifierLoc, NKI_QualType, NKI_TypeLoc, + NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc, + NKI_CXXCtorInitializer, + NKI_NestedNameSpecifier, NKI_Decl, #define DECL(DERIVED, BASE) NKI_##DERIVED##Decl, #include "clang/AST/DeclNodes.inc" @@ -238,7 +245,11 @@ class DynTypedNode { /// Note that this is not supported by all AST nodes. For AST nodes /// that don't have a pointer-defined identity inside the AST, this /// method returns NULL. - const void *getMemoizationData() const { return MemoizationData; } + const void *getMemoizationData() const { + return NodeKind.hasPointerIdentity() + ? *reinterpret_cast(Storage.buffer) + : nullptr; + } /// \brief Prints the node to the given output stream. void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const; @@ -257,6 +268,28 @@ class DynTypedNode { /// FIXME: Implement comparsion for other node types (currently /// only Stmt, Decl, Type and NestedNameSpecifier return memoization data). bool operator<(const DynTypedNode &Other) const { + if (!NodeKind.isSame(Other.NodeKind)) + return NodeKind < Other.NodeKind; + + if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) { + auto TLA = getUnchecked(); + auto TLB = Other.getUnchecked(); + return std::make_pair(TLA.getType().getAsOpaquePtr(), + TLA.getOpaqueData()) < + std::make_pair(TLB.getType().getAsOpaquePtr(), + TLB.getOpaqueData()); + } + + if (ASTNodeKind::getFromNodeKind().isSame( + NodeKind)) { + auto NNSLA = getUnchecked(); + auto NNSLB = Other.getUnchecked(); + return std::make_pair(NNSLA.getNestedNameSpecifier(), + NNSLA.getOpaqueData()) < + std::make_pair(NNSLB.getNestedNameSpecifier(), + NNSLB.getOpaqueData()); + } + assert(getMemoizationData() && Other.getMemoizationData()); return getMemoizationData() < Other.getMemoizationData(); } @@ -270,6 +303,13 @@ class DynTypedNode { if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) return getUnchecked() == Other.getUnchecked(); + if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) + return getUnchecked() == Other.getUnchecked(); + + if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) + return getUnchecked() == + Other.getUnchecked(); + assert(getMemoizationData() && Other.getMemoizationData()); return getMemoizationData() == Other.getMemoizationData(); } @@ -278,6 +318,47 @@ class DynTypedNode { } /// @} + /// \brief Hooks for using DynTypedNode as a key in a DenseMap. + struct DenseMapInfo { + static inline DynTypedNode getEmptyKey() { + DynTypedNode Node; + Node.NodeKind = ASTNodeKind::DenseMapInfo::getEmptyKey(); + return Node; + } + static inline DynTypedNode getTombstoneKey() { + DynTypedNode Node; + Node.NodeKind = ASTNodeKind::DenseMapInfo::getTombstoneKey(); + return Node; + } + static unsigned getHashValue(const DynTypedNode &Val) { + // FIXME: Add hashing support for the remaining types. + if (ASTNodeKind::getFromNodeKind().isSame(Val.NodeKind)) { + auto TL = Val.getUnchecked(); + return llvm::hash_combine(TL.getType().getAsOpaquePtr(), + TL.getOpaqueData()); + } + + if (ASTNodeKind::getFromNodeKind().isSame( + Val.NodeKind)) { + auto NNSL = Val.getUnchecked(); + return llvm::hash_combine(NNSL.getNestedNameSpecifier(), + NNSL.getOpaqueData()); + } + + assert(Val.getMemoizationData()); + return llvm::hash_value(Val.getMemoizationData()); + } + static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS) { + auto Empty = ASTNodeKind::DenseMapInfo::getEmptyKey(); + auto TombStone = ASTNodeKind::DenseMapInfo::getTombstoneKey(); + return (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, Empty) && + ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, Empty)) || + (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, TombStone) && + ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, TombStone)) || + LHS == RHS; + } + }; + private: /// \brief Takes care of converting from and to \c T. template struct BaseConverter; @@ -286,18 +367,18 @@ class DynTypedNode { template struct DynCastPtrConverter { static const T *get(ASTNodeKind NodeKind, const char Storage[]) { if (ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)) - return cast(*reinterpret_cast(Storage)); + return &getUnchecked(NodeKind, Storage); return nullptr; } static const T &getUnchecked(ASTNodeKind NodeKind, const char Storage[]) { assert(ASTNodeKind::getFromNodeKind().isBaseOf(NodeKind)); - return *cast(*reinterpret_cast(Storage)); + return *cast(static_cast( + *reinterpret_cast(Storage))); } static DynTypedNode create(const BaseT &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNode(Node); - Result.MemoizationData = &Node; - new (Result.Storage.buffer) const BaseT * (&Node); + new (Result.Storage.buffer) const void *(&Node); return Result; } }; @@ -306,18 +387,18 @@ class DynTypedNode { template struct PtrConverter { static const T *get(ASTNodeKind NodeKind, const char Storage[]) { if (ASTNodeKind::getFromNodeKind().isSame(NodeKind)) - return *reinterpret_cast(Storage); + return &getUnchecked(NodeKind, Storage); return nullptr; } static const T &getUnchecked(ASTNodeKind NodeKind, const char Storage[]) { assert(ASTNodeKind::getFromNodeKind().isSame(NodeKind)); - return **reinterpret_cast(Storage); + return *static_cast( + *reinterpret_cast(Storage)); } static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); - Result.MemoizationData = &Node; - new (Result.Storage.buffer) const T * (&Node); + new (Result.Storage.buffer) const void *(&Node); return Result; } }; @@ -336,14 +417,12 @@ class DynTypedNode { static DynTypedNode create(const T &Node) { DynTypedNode Result; Result.NodeKind = ASTNodeKind::getFromNodeKind(); - Result.MemoizationData = nullptr; new (Result.Storage.buffer) T(Node); return Result; } }; ASTNodeKind NodeKind; - const void *MemoizationData; /// \brief Stores the data of the node. /// @@ -353,12 +432,9 @@ class DynTypedNode { /// \c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs and /// \c TemplateArguments on the other hand do not have storage or unique /// pointers and thus need to be stored by value. - typedef llvm::AlignedCharArrayUnion< - Decl *, Stmt *, Type *, NestedNameSpecifier *, CXXCtorInitializer *> - KindsByPointer; - llvm::AlignedCharArrayUnion - Storage; + llvm::AlignedCharArrayUnion Storage; }; template @@ -420,6 +496,10 @@ template <> struct DenseMapInfo : clang::ast_type_traits::ASTNodeKind::DenseMapInfo {}; +template <> +struct DenseMapInfo + : clang::ast_type_traits::DynTypedNode::DenseMapInfo {}; + } // end namespace llvm #endif diff --git a/include/clang/AST/ASTVector.h b/include/clang/AST/ASTVector.h index 6ec054582e2..79453bf1087 100644 --- a/include/clang/AST/ASTVector.h +++ b/include/clang/AST/ASTVector.h @@ -384,14 +384,15 @@ void ASTVector::grow(const ASTContext &C, size_t MinSize) { T *NewElts = new (C, llvm::alignOf()) T[NewCapacity]; // Copy the elements over. - if (std::is_class::value) { - std::uninitialized_copy(Begin, End, NewElts); - // Destroy the original elements. - destroy_range(Begin, End); - } - else { - // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove). - memcpy(NewElts, Begin, CurSize * sizeof(T)); + if (Begin != End) { + if (std::is_class::value) { + std::uninitialized_copy(Begin, End, NewElts); + // Destroy the original elements. + destroy_range(Begin, End); + } else { + // Use memcpy for PODs (std::uninitialized_copy optimizes to memmove). + memcpy(NewElts, Begin, CurSize * sizeof(T)); + } } // ASTContext never frees any memory. diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 4e282d68b74..8b80e9f6396 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -56,21 +56,21 @@ class Attr { bool IsLateParsed : 1; bool DuplicatesAllowed : 1; - void* operator new(size_t bytes) throw() { + void *operator new(size_t bytes) LLVM_NOEXCEPT { llvm_unreachable("Attrs cannot be allocated with regular 'new'."); } - void operator delete(void* data) throw() { + void operator delete(void *data) LLVM_NOEXCEPT { llvm_unreachable("Attrs cannot be released with regular 'delete'."); } public: // Forward so that the regular new and delete do not hide global ones. - void* operator new(size_t Bytes, ASTContext &C, - size_t Alignment = 8) throw() { + void *operator new(size_t Bytes, ASTContext &C, + size_t Alignment = 8) LLVM_NOEXCEPT { return ::operator new(Bytes, C, Alignment); } void operator delete(void *Ptr, ASTContext &C, - size_t Alignment) throw() { + size_t Alignment) LLVM_NOEXCEPT { return ::operator delete(Ptr, C, Alignment); } diff --git a/include/clang/AST/BuiltinTypes.def b/include/clang/AST/BuiltinTypes.def index 488cacef0af..85e237a2bf0 100644 --- a/include/clang/AST/BuiltinTypes.def +++ b/include/clang/AST/BuiltinTypes.def @@ -160,6 +160,12 @@ BUILTIN_TYPE(OCLImage1dArray, OCLImage1dArrayTy) BUILTIN_TYPE(OCLImage1dBuffer, OCLImage1dBufferTy) BUILTIN_TYPE(OCLImage2d, OCLImage2dTy) BUILTIN_TYPE(OCLImage2dArray, OCLImage2dArrayTy) +BUILTIN_TYPE(OCLImage2dDepth, OCLImage2dDepthTy) +BUILTIN_TYPE(OCLImage2dArrayDepth, OCLImage2dArrayDepthTy) +BUILTIN_TYPE(OCLImage2dMSAA, OCLImage2dMSAATy) +BUILTIN_TYPE(OCLImage2dArrayMSAA, OCLImage2dArrayMSAATy) +BUILTIN_TYPE(OCLImage2dMSAADepth, OCLImage2dMSAADepthTy) +BUILTIN_TYPE(OCLImage2dArrayMSAADepth, OCLImage2dArrayMSAADepthTy) BUILTIN_TYPE(OCLImage3d, OCLImage3dTy) // OpenCL sampler_t. @@ -168,6 +174,18 @@ BUILTIN_TYPE(OCLSampler, OCLSamplerTy) // OpenCL event_t. BUILTIN_TYPE(OCLEvent, OCLEventTy) +// OpenCL clk_event_t. +BUILTIN_TYPE(OCLClkEvent, OCLClkEventTy) + +// OpenCL queue_t. +BUILTIN_TYPE(OCLQueue, OCLQueueTy) + +// OpenCL ndrange_t. +BUILTIN_TYPE(OCLNDRange, OCLNDRangeTy) + +// OpenCL reserve_id_t. +BUILTIN_TYPE(OCLReserveID, OCLReserveIDTy) + // This represents the type of an expression whose type is // totally unknown, e.g. 'T::foo'. It is permitted for this to // appear in situations where the structure of the type is @@ -227,8 +245,11 @@ PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy) // context. PLACEHOLDER_TYPE(ARCUnbridgedCast, ARCUnbridgedCastTy) +// A placeholder type for OpenMP array sections. +PLACEHOLDER_TYPE(OMPArraySection, OMPArraySectionTy) + #ifdef LAST_BUILTIN_TYPE -LAST_BUILTIN_TYPE(ARCUnbridgedCast) +LAST_BUILTIN_TYPE(OMPArraySection) #undef LAST_BUILTIN_TYPE #endif diff --git a/include/clang/AST/CXXInheritance.h b/include/clang/AST/CXXInheritance.h index 008efb36477..8587260049a 100644 --- a/include/clang/AST/CXXInheritance.h +++ b/include/clang/AST/CXXInheritance.h @@ -155,7 +155,7 @@ class CXXBasePaths { /// \brief Array of the declarations that have been found. This /// array is constructed only if needed, e.g., to iterate over the /// results within LookupResult. - NamedDecl **DeclsFound; + std::unique_ptr DeclsFound; unsigned NumDeclsFound; friend class CXXRecordDecl; @@ -172,15 +172,12 @@ class CXXBasePaths { /// BasePaths - Construct a new BasePaths structure to record the /// paths for a derived-to-base search. - explicit CXXBasePaths(bool FindAmbiguities = true, - bool RecordPaths = true, + explicit CXXBasePaths(bool FindAmbiguities = true, bool RecordPaths = true, bool DetectVirtual = true) - : FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths), - DetectVirtual(DetectVirtual), DetectedVirtual(nullptr), - DeclsFound(nullptr), NumDeclsFound(0) { } - - ~CXXBasePaths() { delete [] DeclsFound; } - + : FindAmbiguities(FindAmbiguities), RecordPaths(RecordPaths), + DetectVirtual(DetectVirtual), DetectedVirtual(nullptr), + NumDeclsFound(0) {} + paths_iterator begin() { return Paths.begin(); } paths_iterator end() { return Paths.end(); } const_paths_iterator begin() const { return Paths.begin(); } diff --git a/include/clang/AST/CharUnits.h b/include/clang/AST/CharUnits.h index 72ca9f5cd67..1d22bccd2e8 100644 --- a/include/clang/AST/CharUnits.h +++ b/include/clang/AST/CharUnits.h @@ -130,6 +130,14 @@ namespace clang { return (Quantity & -Quantity) == Quantity; } + /// Test whether this is a multiple of the other value. + /// + /// Among other things, this promises that + /// self.RoundUpToAlignment(N) will just return self. + bool isMultipleOf(CharUnits N) const { + return (*this % N) == 0; + } + // Arithmetic operators. CharUnits operator* (QuantityType N) const { return CharUnits(Quantity * N); @@ -172,10 +180,20 @@ namespace clang { /// Given that this is a non-zero alignment value, what is the /// alignment at the given offset? - CharUnits alignmentAtOffset(CharUnits offset) { + CharUnits alignmentAtOffset(CharUnits offset) const { + assert(Quantity != 0 && "offsetting from unknown alignment?"); return CharUnits(llvm::MinAlign(Quantity, offset.Quantity)); } + /// Given that this is the alignment of the first element of an + /// array, return the minimum alignment of any element in the array. + CharUnits alignmentOfArrayElement(CharUnits elementSize) const { + // Since we don't track offsetted alignments, the alignment of + // the second element (or any odd element) will be minimally + // aligned. + return alignmentAtOffset(elementSize); + } + }; // class CharUnit } // namespace clang diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h index 9b05d397baf..6a803836e84 100644 --- a/include/clang/AST/CommentSema.h +++ b/include/clang/AST/CommentSema.h @@ -79,12 +79,8 @@ class Sema { /// Returns a copy of array, owned by Sema's allocator. template ArrayRef copyArray(ArrayRef Source) { - size_t Size = Source.size(); - if (Size != 0) { - T *Mem = Allocator.Allocate(Size); - std::uninitialized_copy(Source.begin(), Source.end(), Mem); - return llvm::makeArrayRef(Mem, Size); - } + if (!Source.empty()) + return Source.copy(Allocator); return None; } diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index c1e98e757e1..cc80a684366 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -24,6 +24,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" +#include "clang/AST/ExprOpenMP.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" @@ -42,7 +43,7 @@ OPERATOR(PostInc) OPERATOR(PostDec) OPERATOR(PreInc) OPERATOR(PreDec) \ OPERATOR(AddrOf) OPERATOR(Deref) OPERATOR(Plus) OPERATOR(Minus) \ OPERATOR(Not) OPERATOR(LNot) OPERATOR(Real) OPERATOR(Imag) \ - OPERATOR(Extension) + OPERATOR(Extension) OPERATOR(Coawait) // All binary operators (excluding compound assign operators). #define BINOP_LIST() \ @@ -1550,6 +1551,10 @@ DEF_TRAVERSE_DECL(FunctionTemplateDecl, { TRY_TO(TraverseFunctionInstantiations(D)); }) +DEF_TRAVERSE_DECL(BuiltinTemplateDecl, { + TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters())); +}) + DEF_TRAVERSE_DECL(TemplateTemplateParmDecl, { // D is the "T" in something like // template