diff --git a/.ci/generate_test_report_github.py b/.ci/generate_test_report_github.py index 7242264723cbf..6785e82f3440b 100644 --- a/.ci/generate_test_report_github.py +++ b/.ci/generate_test_report_github.py @@ -8,10 +8,15 @@ import generate_test_report_lib -PLATFORM_TITLES = { - "Windows": ":window: Windows x64 Test Results", - "Linux": ":penguin: Linux x64 Test Results", -} +def compute_platform_title() -> str: + logo = ":window:" if platform.system() == "Windows" else ":penguin:" + # On Linux the machine value is x86_64 on Windows it is AMD64. + if platform.machine() == "x86_64" or platform.machine() == "AMD64": + arch = "x64" + else: + arch = platform.machine() + return f"{logo} {platform.system()} {arch} Test Results" + if __name__ == "__main__": parser = argparse.ArgumentParser() @@ -22,7 +27,7 @@ args = parser.parse_args() report = generate_test_report_lib.generate_report_from_files( - PLATFORM_TITLES[platform.system()], args.return_code, args.build_test_logs + compute_platform_title(), args.return_code, args.build_test_logs ) print(report) diff --git a/.ci/generate_test_report_lib.py b/.ci/generate_test_report_lib.py index 5026c292a7934..36c95852452ac 100644 --- a/.ci/generate_test_report_lib.py +++ b/.ci/generate_test_report_lib.py @@ -98,6 +98,23 @@ def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]: ) return output +def get_failures(junit_objects) -> dict[str, list[tuple[str, str]]]: + failures = {} + for results in junit_objects: + for testsuite in results: + for test in testsuite: + if ( + not test.is_passed + and test.result + and isinstance(test.result[0], Failure) + ): + if failures.get(testsuite.name) is None: + failures[testsuite.name] = [] + failures[testsuite.name].append( + (test.classname + "/" + test.name, test.result[0].text) + ) + return failures + # Set size_limit to limit the byte size of the report. The default is 1MB as this # is the most that can be put into an annotation. If the generated report exceeds @@ -113,7 +130,7 @@ def generate_report( size_limit=1024 * 1024, list_failures=True, ): - failures = {} + failures = get_failures(junit_objects) tests_run = 0 tests_skipped = 0 tests_failed = 0 @@ -124,18 +141,6 @@ def generate_report( tests_skipped += testsuite.skipped tests_failed += testsuite.failures - for test in testsuite: - if ( - not test.is_passed - and test.result - and isinstance(test.result[0], Failure) - ): - if failures.get(testsuite.name) is None: - failures[testsuite.name] = [] - failures[testsuite.name].append( - (test.classname + "/" + test.name, test.result[0].text) - ) - report = [f"# {title}", ""] if tests_run == 0: @@ -258,7 +263,7 @@ def plural(num_tests): return report -def generate_report_from_files(title, return_code, build_log_files): +def load_info_from_files(build_log_files): junit_files = [ junit_file for junit_file in build_log_files if junit_file.endswith(".xml") ] @@ -271,6 +276,9 @@ def generate_report_from_files(title, return_code, build_log_files): ninja_logs.append( [log_line.strip() for log_line in ninja_log_file_handle.readlines()] ) - return generate_report( - title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs - ) + return [JUnitXml.fromfile(p) for p in junit_files], ninja_logs + + +def generate_report_from_files(title, return_code, build_log_files): + junit_objects, ninja_logs = load_info_from_files(build_log_files) + return generate_report(title, return_code, junit_objects, ninja_logs) diff --git a/.ci/metrics/metrics.py b/.ci/metrics/metrics.py index 82158ff598ebb..a6d6edbd547e7 100644 --- a/.ci/metrics/metrics.py +++ b/.ci/metrics/metrics.py @@ -40,6 +40,7 @@ GITHUB_JOB_TO_TRACK = { "github_llvm_premerge_checks": { "Build and Test Linux": "premerge_linux", + "Build and Test Linux AArch64": "premerge_linux_aarch64", "Build and Test Windows": "premerge_windows", }, "github_libcxx_premerge_checks": { diff --git a/.ci/utils.sh b/.ci/utils.sh index 87afbbd6cdd31..5d32968babb39 100644 --- a/.ci/utils.sh +++ b/.ci/utils.sh @@ -56,6 +56,7 @@ function start-group { export PIP_BREAK_SYSTEM_PACKAGES=1 pip install -q -r "${MONOREPO_ROOT}"/.ci/all_requirements.txt -if [[ "$GITHUB_ACTIONS" != "" ]]; then +# The ARM64 builders run on AWS and don't have access to the GCS cache. +if [[ "$GITHUB_ACTIONS" != "" ]] && [[ "$RUNNER_ARCH" != "ARM64" ]]; then python .ci/cache_lit_timing_files.py download fi diff --git a/.github/new-prs-labeler.yml b/.github/new-prs-labeler.yml index c49fd1dd3cc7f..efdc42d349195 100644 --- a/.github/new-prs-labeler.yml +++ b/.github/new-prs-labeler.yml @@ -1096,8 +1096,8 @@ clang:openmp: - llvm/test/Transforms/OpenMP/** clang:temporal-safety: - - clang/include/clang/Analysis/Analyses/LifetimeSafety* - - clang/lib/Analysis/LifetimeSafety* + - clang/include/clang/Analysis/Analyses/LifetimeSafety/** + - clang/lib/Analysis/LifetimeSafety/** - clang/unittests/Analysis/LifetimeSafety* - clang/test/Sema/*lifetime-safety* - clang/test/Sema/*lifetime-analysis* diff --git a/.github/workflows/build-ci-container-tooling.yml b/.github/workflows/build-ci-container-tooling.yml index 8095a68cfda9e..c77c78617666d 100644 --- a/.github/workflows/build-ci-container-tooling.yml +++ b/.github/workflows/build-ci-container-tooling.yml @@ -1,4 +1,4 @@ -name: Build CI Container +name: Build CI Tooling Containers permissions: contents: read @@ -72,7 +72,7 @@ jobs: - name: Test Container run: | # Use --pull=never to ensure we are testing the just built image. - podman run --pull=never --rm -it ${{ steps.vars.outputs.container-name-format-tag }} /usr/bin/bash -x -c 'cd $HOME && clang-format --version | grep version && black --version | grep black' + podman run --pull=never --rm -it ${{ steps.vars.outputs.container-name-format-tag }} /usr/bin/bash -x -c 'cd $HOME && clang-format --version | grep version && git-clang-format -h | grep usage && black --version | grep black' podman run --pull=never --rm -it ${{ steps.vars.outputs.container-name-lint-tag }} /usr/bin/bash -x -c 'cd $HOME && clang-tidy --version | grep version && clang-tidy-diff.py -h | grep usage' push-ci-container: @@ -101,7 +101,7 @@ jobs: } podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io - for f in $(find . -iname *.tar); do + for f in $(find . -iname '*.tar'); do image_name=$(podman load -q -i $f | sed 's/Loaded image: //g') push_container $image_name diff --git a/.github/workflows/build-ci-container.yml b/.github/workflows/build-ci-container.yml index 01f1b8dc4f990..027c558afdd0b 100644 --- a/.github/workflows/build-ci-container.yml +++ b/.github/workflows/build-ci-container.yml @@ -103,7 +103,7 @@ jobs: } podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io - for f in $(find . -iname *.tar); do + for f in $(find . -iname '*.tar'); do image_name=$(podman load -q -i $f | sed 's/Loaded image: //g') push_container $image_name diff --git a/.github/workflows/containers/github-action-ci-tooling/Dockerfile b/.github/workflows/containers/github-action-ci-tooling/Dockerfile index 7a5d8a3be53fd..7d64562876628 100644 --- a/.github/workflows/containers/github-action-ci-tooling/Dockerfile +++ b/.github/workflows/containers/github-action-ci-tooling/Dockerfile @@ -10,7 +10,8 @@ RUN apt-get update && \ tar -xvJf llvm.tar.xz -C /llvm-extract \ # Only unpack these tools to save space on Github runner. LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-tidy \ - LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format && \ + LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format \ + LLVM-${LLVM_VERSION}-Linux-X64/bin/git-clang-format && \ rm llvm.tar.xz @@ -35,7 +36,9 @@ RUN apt-get update && \ FROM base AS ci-container-code-format ARG LLVM_VERSION -COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format ${LLVM_SYSROOT}/bin/clang-format +COPY --from=llvm-downloader /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/clang-format \ + /llvm-extract/LLVM-${LLVM_VERSION}-Linux-X64/bin/git-clang-format \ + ${LLVM_SYSROOT}/bin/ ENV PATH=${LLVM_SYSROOT}/bin:${PATH} diff --git a/.github/workflows/containers/github-action-ci-windows/Dockerfile b/.github/workflows/containers/github-action-ci-windows/Dockerfile index 640d34da02532..9ddf5017bc020 100644 --- a/.github/workflows/containers/github-action-ci-windows/Dockerfile +++ b/.github/workflows/containers/github-action-ci-windows/Dockerfile @@ -90,7 +90,7 @@ RUN powershell -Command \ RUN git config --system core.longpaths true & \ git config --global core.autocrlf false -ARG RUNNER_VERSION=2.328.0 +ARG RUNNER_VERSION=2.329.0 ENV RUNNER_VERSION=$RUNNER_VERSION RUN powershell -Command \ diff --git a/.github/workflows/containers/github-action-ci/Dockerfile b/.github/workflows/containers/github-action-ci/Dockerfile index dc0c9cabc7f01..1b376dd4420b3 100644 --- a/.github/workflows/containers/github-action-ci/Dockerfile +++ b/.github/workflows/containers/github-action-ci/Dockerfile @@ -2,7 +2,7 @@ FROM docker.io/library/ubuntu:24.04 AS base ENV LLVM_SYSROOT=/opt/llvm FROM base AS stage1-toolchain -ENV LLVM_VERSION=21.1.1 +ENV LLVM_VERSION=21.1.3 RUN apt-get update && \ apt-get install -y \ @@ -62,7 +62,6 @@ RUN apt-get update && \ # Having a symlink from python to python3 enables code sharing between # the Linux and Windows pipelines. python3-pip \ - python3-venv \ file \ tzdata \ python-is-python3 && \ @@ -100,7 +99,7 @@ WORKDIR /home/gha FROM ci-container AS ci-container-agent -ENV GITHUB_RUNNER_VERSION=2.328.0 +ENV GITHUB_RUNNER_VERSION=2.329.0 RUN mkdir actions-runner && \ cd actions-runner && \ diff --git a/.github/workflows/pr-code-format.yml b/.github/workflows/pr-code-format.yml index 1e0dc7045c1cc..2b85d8b59869c 100644 --- a/.github/workflows/pr-code-format.yml +++ b/.github/workflows/pr-code-format.yml @@ -12,6 +12,8 @@ on: jobs: code_formatter: runs-on: ubuntu-24.04 + container: + image: 'ghcr.io/llvm/ci-ubuntu-24.04-format' timeout-minutes: 30 concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} @@ -23,6 +25,14 @@ jobs: with: fetch-depth: 2 + # We need to set the repo checkout as safe, otherwise tj-actions/changed-files + # will fail due to the changed ownership inside the container. + # TODO(boomanaiden154): We should probably fix this by having the default user + # in the container have the same ID as the GHA user on the host. + - name: Set Safe Directory + run: | + chown -R root $(pwd) + - name: Get changed files id: changed-files uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5 @@ -39,24 +49,6 @@ jobs: echo "Formatting files:" echo "$CHANGED_FILES" - # The clang format version should always be upgraded to the first version - # of a release cycle (x.1.0) or the last version of a release cycle, or - # if there have been relevant clang-format backports. - - name: Install clang-format - uses: aminya/setup-cpp@a276e6e3d1db9160db5edc458e99a30d3b109949 # v1.7.1 - with: - clangformat: 21.1.0 - - - name: Setup Python env - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 - with: - python-version: '3.13' - cache: 'pip' - cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt' - - - name: Install python dependencies - run: pip install -r llvm/utils/git/requirements_formatting.txt - - name: Run code formatter env: GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} diff --git a/.github/workflows/premerge.yaml b/.github/workflows/premerge.yaml index a9c107e4a5f08..03c0c01d382ff 100644 --- a/.github/workflows/premerge.yaml +++ b/.github/workflows/premerge.yaml @@ -24,17 +24,45 @@ concurrency: jobs: premerge-checks-linux: - name: Build and Test Linux + name: Build and Test Linux${{ (startsWith(matrix.runs-on, 'depot-ubuntu-24.04-arm') && ' AArch64') || '' }} if: >- github.repository_owner == 'llvm' && (github.event_name != 'pull_request' || github.event.action != 'closed') - runs-on: llvm-premerge-linux-runners + strategy: + fail-fast: false + matrix: + runs-on: + - depot-ubuntu-24.04-arm-16 + - llvm-premerge-linux-runners + runs-on: ${{ matrix.runs-on }} + container: + # The llvm-premerge agents are already containers and running the + # this same image, so we can't use a container for the github action + # job. The depot containers are running on VMs, so we can use a + # container. This helps ensure the build environment is as close + # as possible on both the depot runners and the llvm-premerge runners. + image: ${{ (startsWith(matrix.runs-on, 'depot-ubuntu-24.04-arm') && format('ghcr.io/{0}/arm64v8/ci-ubuntu-24.04',github.repository_owner) ) || null }} + # --privileged is needed to run the lldb tests that disable aslr. + # The SCCACHE environment variables are need to be copied from the host + # to the container to make sure it is configured correctly to use the + # depot cache. + options: >- + --privileged + --env SCCACHE_WEBDAV_ENDPOINT + --env SCCACHE_WEBDAV_TOKEN + defaults: + run: + # The run step defaults to using sh as the shell when running in a + # container, so make bash the default to ensure consistency between + # container and non-container jobs. + shell: bash steps: - name: Checkout LLVM uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: fetch-depth: 2 - name: Build and Test + continue-on-error: ${{ runner.arch == 'ARM64' }} run: | git config --global --add safe.directory '*' @@ -54,11 +82,16 @@ jobs: export CC=/opt/llvm/bin/clang export CXX=/opt/llvm/bin/clang++ - # This environment variable is passes into the container through the - # runner pod definition. This differs between our two clusters which - # why we do not hardcode it. - export SCCACHE_GCS_BUCKET=$CACHE_GCS_BUCKET - export SCCACHE_GCS_RW_MODE=READ_WRITE + # The linux-premerge runners are hosted on GCP and have a different + # cache setup than the depot runners. + if [[ "${{ matrix.runs-on }}" = "llvm-premerge-linux-runners" ]]; then + # This environment variable is passes into the container through the + # runner pod definition. This differs between our two clusters which + # why we do not hardcode it. + export SCCACHE_GCS_BUCKET=$CACHE_GCS_BUCKET + export SCCACHE_GCS_RW_MODE=READ_WRITE + fi + env # Set the idle timeout to zero to ensure sccache runs for the # entire duration of the job. Otherwise it might stop if we run @@ -78,7 +111,7 @@ jobs: if: '!cancelled()' uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: Premerge Artifacts (Linux) + name: Premerge Artifacts (Linux ${{ runner.arch }}) path: artifacts/ retention-days: 5 include-hidden-files: 'true' diff --git a/.github/workflows/release-asset-audit.py b/.github/workflows/release-asset-audit.py index 23b901a476dc0..0cff6c695921f 100644 --- a/.github/workflows/release-asset-audit.py +++ b/.github/workflows/release-asset-audit.py @@ -54,6 +54,8 @@ def _get_uploaders(release_version): "tru", "tstellar", "github-actions[bot]", + "c-rhodes", + "dyung", ] ) diff --git a/.github/workflows/release-binaries-save-stage/action.yml b/.github/workflows/release-binaries-save-stage/action.yml deleted file mode 100644 index 84ccf98c23a82..0000000000000 --- a/.github/workflows/release-binaries-save-stage/action.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Save Stage -description: >- - Upload the source and binary directories from a build stage so that they - can be re-used in the next stage. This action is used to the release - binaries workflow into multiple stages to avoid the 6 hour timeout on - the GitHub hosted runners. -inputs: - build-prefix: - description: "Directory containing the build directory." - required: true - type: 'string' - -permissions: - contents: read - -runs: - using: "composite" - steps: - # We need to create an archive of the build directory, because it has too - # many files to upload. - - name: Package Build and Source Directories - shell: bash - run: | - # Remove .git/config to avoid leaking GITHUB_TOKEN stored there. - # See https://unit42.paloaltonetworks.com/github-repo-artifacts-leak-tokens/ - rm -Rf .git/config - # Windows does not support symlinks, so we need to dereference them. - tar --exclude build/ ${{ (runner.os == 'Windows' && '-h') || '' }} -c . | zstd -T0 -c > ../llvm-project.tar.zst - mv ../llvm-project.tar.zst . - tar -C ${{ inputs.build-prefix }} -c build/ | zstd -T0 -c > build.tar.zst - - - name: Upload Stage 1 Source - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: ${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-source - path: llvm-project.tar.zst - retention-days: 2 - - - name: Upload Stage 1 Build Dir - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: ${{ runner.os}}-${{ runner.arch }}-${{ github.job }}-build - path: build.tar.zst - retention-days: 2 diff --git a/.github/workflows/release-binaries-setup-stage/action.yml b/.github/workflows/release-binaries-setup-stage/action.yml deleted file mode 100644 index 475a25fa6b772..0000000000000 --- a/.github/workflows/release-binaries-setup-stage/action.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Setup Stage -description: >- - Setup the next stage of the release binaries workflow. This sets up the - environment correctly for a new stage of the release binaries workflow - and also restores the source and build directory from the previous stage. - -inputs: - previous-artifact: - description: >- - A unique descriptor for the artifact from the previous stage. This will - be used to construct the final artifact pattern, which is: - $RUNNER_OS-$RUNNER_ARCH-$PREVIOUS_ARTIFACT-* - required: false - type: 'string' - -outputs: - build-prefix: - description: "Directory containing the build directory." - value: ${{ steps.build-prefix.outputs.build-prefix }} - -runs: - using: "composite" - steps: - - name: Install Ninja - uses: llvm/actions/install-ninja@a1ea791b03c8e61f53a0e66f2f73db283aa0f01e # main - - - name: Setup Windows - if: startsWith(runner.os, 'Windows') - uses: llvm/actions/setup-windows@main - with: - arch: amd64 - - - name: Set Build Prefix - id: build-prefix - shell: bash - run: | - build_prefix=`pwd` - if [ "${{ runner.os }}" = "Linux" ]; then - sudo chown $USER:$USER /mnt/ - build_prefix=/mnt/ - fi - echo "build-prefix=$build_prefix" >> $GITHUB_OUTPUT - - - name: Download Previous Stage Artifact - if: ${{ inputs.previous-artifact }} - id: download - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 - with: - pattern: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.previous-artifact }}-* - merge-multiple: true - - - name: Unpack Artifact - if: ${{ steps.download.outputs.download-path }} - shell: bash - run: | - tar --zstd -xf llvm-project.tar.zst - rm llvm-project.tar.zst - tar --zstd -C ${{ steps.build-prefix.outputs.build-prefix}} -xf build.tar.zst - rm build.tar.zst diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml index cba48e4d0c70a..83969b5490685 100644 --- a/.github/workflows/release-binaries.yml +++ b/.github/workflows/release-binaries.yml @@ -194,40 +194,30 @@ jobs: runs-on: ${{ needs.prepare.outputs.build-runs-on }} steps: - - name: Checkout Actions - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - ref: ${{ (github.event_name == 'pull_request' && github.sha) || 'main' }} - sparse-checkout: | - .github/workflows/ - sparse-checkout-cone-mode: false - # Check out outside of working directory so the source checkout doesn't - # remove it. - path: workflows - - # actions/checkout does not support paths outside of the GITHUB_WORKSPACE. - # Also, anything that we put inside of GITHUB_WORKSPACE will be overwritten - # by future actions/checkout steps. Therefore, in order to checkout the - # latest actions from main, we need to first checkout out the actions inside of - # GITHUB_WORKSPACE (see previous step), then use actions/checkout to checkout - # the code being built and the move the actions from main back into GITHUB_WORKSPACE, - # becasue the uses on composite actions only reads workflows from inside GITHUB_WORKSPACE. - - shell: bash - run: mv workflows ../workflows-main - - name: Checkout LLVM uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: ref: ${{ needs.prepare.outputs.ref }} - - name: Copy main workflows - shell: bash - run: | - mv ../workflows-main . + - name: Install Ninja + uses: llvm/actions/install-ninja@a1ea791b03c8e61f53a0e66f2f73db283aa0f01e # main + + - name: Setup Windows + if: startsWith(runner.os, 'Windows') + uses: llvm/actions/setup-windows@main + with: + arch: amd64 - - name: Setup Stage + - name: Set Build Prefix id: setup-stage - uses: ./workflows-main/.github/workflows/release-binaries-setup-stage + shell: bash + run: | + build_prefix=`pwd` + if [ "${{ runner.os }}" = "Linux" ]; then + sudo chown $USER:$USER /mnt/ + build_prefix=/mnt/ + fi + echo "build-prefix=$build_prefix" >> $GITHUB_OUTPUT - name: Configure id: build @@ -258,17 +248,11 @@ jobs: path: | ${{ needs.prepare.outputs.release-binary-filename }} - # Clean up some build files to reduce size of artifact. - - name: Clean Up Build Directory - shell: bash + - name: Run Tests + # These almost always fail so don't let them fail the build and prevent the uploads. + continue-on-error: true run: | - find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname ${{ needs.prepare.outputs.release-binary-filename }} -delete - find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname _CPack_Packages -prune -exec rm -r {} + - - - name: Save Stage - uses: ./workflows-main/.github/workflows/release-binaries-save-stage - with: - build-prefix: ${{ steps.setup-stage.outputs.build-prefix }} + ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build stage2-check-all upload-release-binaries: name: "Upload Release Binaries" @@ -327,31 +311,3 @@ jobs: --release ${{ needs.prepare.outputs.release-version }} \ upload \ --files ${{ needs.prepare.outputs.release-binary-filename }}* - - test-release: - name: "Test Release" - needs: - - prepare - - build-release-package - if: >- - github.repository_owner == 'llvm' - runs-on: ${{ needs.prepare.outputs.test-runs-on }} - steps: - - name: Checkout Actions - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - ref: ${{ (github.event_name == 'pull_request' && github.sha) || 'main' }} - sparse-checkout: | - .github/workflows/ - sparse-checkout-cone-mode: false - path: workflows - - name: Setup Stage - id: setup-stage - uses: ./workflows/.github/workflows/release-binaries-setup-stage - with: - previous-artifact: build-release-package - - - name: Run Tests - shell: bash - run: | - ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build stage2-check-all diff --git a/bolt/docs/BinaryAnalysis.md b/bolt/docs/BinaryAnalysis.md index b13410cd96355..07f096eef784e 100644 --- a/bolt/docs/BinaryAnalysis.md +++ b/bolt/docs/BinaryAnalysis.md @@ -1,7 +1,7 @@ # BOLT-based binary analysis As part of post-link-time optimizing, BOLT needs to perform a range of analyses -on binaries such as recontructing control flow graphs, and more. +on binaries such as reconstructing control flow graphs, and more. The `llvm-bolt-binary-analysis` tool enables running requested binary analyses on binaries, and generating reports. It does this by building on top of the diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md index 151399d69f213..43ceceee7de45 100644 --- a/bolt/docs/CommandLineArgumentReference.md +++ b/bolt/docs/CommandLineArgumentReference.md @@ -375,7 +375,7 @@ - `--use-old-text` - Re-use space in old .text if possible (relocation mode) + Reuse space in old .text if possible (relocation mode) - `-v ` diff --git a/bolt/docs/RuntimeLibrary.md b/bolt/docs/RuntimeLibrary.md index 58d9497a195b2..b969ebd3e3547 100644 --- a/bolt/docs/RuntimeLibrary.md +++ b/bolt/docs/RuntimeLibrary.md @@ -15,7 +15,7 @@ However, this approach quickly becomes awkward if we want to insert a lot of cod Currently, our runtime library is written in C++ and contains code that helps us instrument a binary. ### Limitations -Our library is not written with regular C++ code as it is not linked against any other libraries (this means we cannnot rely on anything defined on libstdc++, glibc, libgcc etc), but is self sufficient. In runtime/CMakeLists.txt, we can see it is built with -ffreestanding, which requires the compiler to avoid using a runtime library by itself. +Our library is not written with regular C++ code as it is not linked against any other libraries (this means we cannot rely on anything defined on libstdc++, glibc, libgcc etc), but is self sufficient. In runtime/CMakeLists.txt, we can see it is built with -ffreestanding, which requires the compiler to avoid using a runtime library by itself. While this requires us to make our own syscalls, it does simplify our linker a lot, which is very limited and can only do basic function name resolving. However, this is a big improvement in comparison with programmatically generating the code in assembly language using MCInsts. diff --git a/bolt/docs/doxygen.cfg.in b/bolt/docs/doxygen.cfg.in index 538285f47d924..de8b1f7bd6b3d 100644 --- a/bolt/docs/doxygen.cfg.in +++ b/bolt/docs/doxygen.cfg.in @@ -1070,7 +1070,7 @@ HTML_STYLESHEET = # defined cascading style sheet that is included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefor more robust against future updates. +# standard style sheet and is therefore more robust against future updates. # Doxygen will copy the style sheet file to the output directory. For an example # see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h index f5e9887b56f70..7b10b2d28d7e3 100644 --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -1336,7 +1336,7 @@ class BinaryFunction { ColdCodeSectionName = Name.str(); } - /// Return true iif the function will halt execution on entry. + /// Return true if the function will halt execution on entry. bool trapsOnEntry() const { return TrapsOnEntry; } /// Make the function always trap on entry. Other than the trap instruction, diff --git a/bolt/include/bolt/Core/DIEBuilder.h b/bolt/include/bolt/Core/DIEBuilder.h index 4c3c277adf422..95e958f16cffd 100644 --- a/bolt/include/bolt/Core/DIEBuilder.h +++ b/bolt/include/bolt/Core/DIEBuilder.h @@ -60,7 +60,7 @@ class DIEBuilder { uint32_t UnitLength = 0; bool IsConstructed = false; // A map of DIE offsets in original DWARF section to DIE ID. - // Whih is used to access DieInfoVector. + // Which is used to access DieInfoVector. std::unordered_map DIEIDMap; // Some STL implementations don't have a noexcept move constructor for diff --git a/bolt/include/bolt/Core/DebugData.h b/bolt/include/bolt/Core/DebugData.h index 814978965ce3a..7c8ea12ee3ee3 100644 --- a/bolt/include/bolt/Core/DebugData.h +++ b/bolt/include/bolt/Core/DebugData.h @@ -326,8 +326,8 @@ class DebugAddrWriter { /// Write out entries in to .debug_addr section for CUs. virtual std::optional finalize(const size_t BufferSize); - /// Return buffer with all the entries in .debug_addr already writen out using - /// update(...). + /// Return buffer with all the entries in .debug_addr already written out + /// using update(...). virtual std::unique_ptr releaseBuffer() { return std::move(Buffer); } @@ -409,7 +409,7 @@ class DebugAddrWriter { std::mutex WriterMutex; std::unique_ptr Buffer; std::unique_ptr AddressStream; - /// Used to track sections that were not modified so that they can be re-used. + /// Used to track sections that were not modified so that they can be reused. static DenseMap UnmodifiedAddressOffsets; }; diff --git a/bolt/include/bolt/Core/DebugNames.h b/bolt/include/bolt/Core/DebugNames.h index cc4e13a481b2d..4ec49ca7207b5 100644 --- a/bolt/include/bolt/Core/DebugNames.h +++ b/bolt/include/bolt/Core/DebugNames.h @@ -65,7 +65,7 @@ class DWARF5AcceleratorTable { void setCurrentUnit(DWARFUnit &Unit, const uint64_t UnitStartOffset); /// Emit Accelerator table. void emitAccelTable(); - /// Returns true if the table was crated. + /// Returns true if the table was created. bool isCreated() const { return NeedToCreate; } /// Returns buffer containing the accelerator table. std::unique_ptr releaseBuffer() { @@ -91,7 +91,7 @@ class DWARF5AcceleratorTable { uint64_t CurrentUnitOffset = 0; const DWARFUnit *CurrentUnit = nullptr; std::unordered_map AbbrevTagToIndexMap; - /// Contains a map of TU hashes to a Foreign TU indecies. + /// Contains a map of TU hashes to a Foreign TU indices. /// This is used to reduce the size of Foreign TU list since there could be /// multiple TUs with the same hash. DenseMap TUHashToIndexMap; diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h index 2772de73081d1..d666c10885ad5 100644 --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -432,7 +432,7 @@ class MCPlusBuilder { return Analysis->isConditionalBranch(Inst); } - /// Returns true if Inst is a condtional move instruction + /// Returns true if Inst is a conditional move instruction virtual bool isConditionalMove(const MCInst &Inst) const { llvm_unreachable("not implemented"); return false; @@ -1564,7 +1564,7 @@ class MCPlusBuilder { } /// Get the default def_in and live_out registers for the function - /// Currently only used for the Stoke optimzation + /// Currently only used for the Stoke optimization virtual void getDefaultDefIn(BitVector &Regs) const { llvm_unreachable("not implemented"); } diff --git a/bolt/include/bolt/Passes/FrameAnalysis.h b/bolt/include/bolt/Passes/FrameAnalysis.h index d71c338bdcc37..5ce85be26cc48 100644 --- a/bolt/include/bolt/Passes/FrameAnalysis.h +++ b/bolt/include/bolt/Passes/FrameAnalysis.h @@ -37,7 +37,7 @@ struct FrameIndexEntry { int64_t StackOffset; uint8_t Size; - /// If this is false, we will never atempt to remove or optimize this + /// If this is false, we will never attempt to remove or optimize this /// instruction. We just use it to keep track of stores we don't fully /// understand but we know it may write to a frame position. bool IsSimple; diff --git a/bolt/include/bolt/Passes/LongJmp.h b/bolt/include/bolt/Passes/LongJmp.h index df3ea9620918a..84da4535648b2 100644 --- a/bolt/include/bolt/Passes/LongJmp.h +++ b/bolt/include/bolt/Passes/LongJmp.h @@ -30,7 +30,7 @@ namespace bolt { /// 64-bit range, we guarantee it can reach any code location. /// class LongJmpPass : public BinaryFunctionPass { - /// Used to implement stub grouping (re-using a stub from one function into + /// Used to implement stub grouping (reusing a stub from one function into /// another) using StubTy = std::pair; using StubGroupTy = SmallVector; diff --git a/bolt/include/bolt/Passes/ProfileQualityStats.h b/bolt/include/bolt/Passes/ProfileQualityStats.h index 86fc88cefc10e..ee74b12bd79bb 100644 --- a/bolt/include/bolt/Passes/ProfileQualityStats.h +++ b/bolt/include/bolt/Passes/ProfileQualityStats.h @@ -49,7 +49,7 @@ // aggregates the block gaps into 2 values for the function: "weighted" is the // weighted average of the block conservation gaps, where the weights depend on // each block's execution count and instruction count; "worst" is the worst -// (biggest) block gap acorss all basic blocks in the function with an execution +// (biggest) block gap across all basic blocks in the function with an execution // count of > 500. The pass then reports the 95th percentile of the weighted and // worst values of the 1000 functions in a single BOLT-INFO line. The smaller // the reported values are, the better the BOLT profile satisfies the function diff --git a/bolt/include/bolt/Passes/ReorderAlgorithm.h b/bolt/include/bolt/Passes/ReorderAlgorithm.h index 95d9e831ec68b..42bb33370cf7c 100644 --- a/bolt/include/bolt/Passes/ReorderAlgorithm.h +++ b/bolt/include/bolt/Passes/ReorderAlgorithm.h @@ -26,7 +26,7 @@ namespace bolt { /// Objects of this class implement various basic block clustering algorithms. /// Basic block clusters are chains of basic blocks that should be laid out -/// in this order to maximize performace. These algorithms group basic blocks +/// in this order to maximize performance. These algorithms group basic blocks /// into clusters using execution profile data and various heuristics. class ClusterAlgorithm { public: diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h index 624245650a092..cab346b5aebc5 100644 --- a/bolt/include/bolt/Rewrite/DWARFRewriter.h +++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h @@ -128,7 +128,7 @@ class DWARFRewriter { CUOffsetMap finalizeTypeSections(DIEBuilder &DIEBlder, DIEStreamer &Streamer, GDBIndex &GDBIndexSection); - /// Process and write out CUs that are passsed in. + /// Process and write out CUs that are passed in. void finalizeCompileUnits(DIEBuilder &DIEBlder, DIEStreamer &Streamer, CUOffsetMap &CUMap, const std::list &CUs, diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 206d8eef40288..46b3372642330 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -844,7 +844,7 @@ BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address, auto isSibling = std::bind(&BinaryContext::areRelatedFragments, this, &Function, std::placeholders::_1); assert(llvm::all_of(JT->Parents, isSibling) && - "cannot re-use jump table of a different function"); + "cannot reuse jump table of a different function"); (void)isSibling; if (opts::Verbosity > 2) { this->outs() << "BOLT-INFO: multiple fragments access the same jump table" @@ -860,7 +860,7 @@ BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address, return JT->getFirstLabel(); } - // Re-use the existing symbol if possible. + // Reuse the existing symbol if possible. MCSymbol *JTLabel = nullptr; if (BinaryData *Object = getBinaryDataAtAddress(Address)) { if (!isInternalSymbolName(Object->getSymbol()->getName())) diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 96878925eccad..4dfd4ba6f611b 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -3875,7 +3875,7 @@ uint64_t BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const { if (FunctionSymbol == Symbol) return 0; - // Check all secondary entries available as either basic blocks or lables. + // Check all secondary entries available as either basic blocks or labels. uint64_t NumEntries = 1; for (const BinaryBasicBlock *BB : BasicBlocks) { MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB); diff --git a/bolt/lib/Core/BinaryFunctionCallGraph.cpp b/bolt/lib/Core/BinaryFunctionCallGraph.cpp index f0c46a82fc74e..af2241998c93b 100644 --- a/bolt/lib/Core/BinaryFunctionCallGraph.cpp +++ b/bolt/lib/Core/BinaryFunctionCallGraph.cpp @@ -122,7 +122,7 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData, // create a node for a function unless it was the target of a call from // a hot block. The alternative would be to set the count to one or // accumulate the number of calls from the callsite into the function - // samples. Results from perfomance testing seem to favor the zero + // samples. Results from performance testing seem to favor the zero // count though, so I'm leaving it this way for now. return Cg.addNode(Function, Size, Function->getKnownExecutionCount()); } diff --git a/bolt/lib/Core/DIEBuilder.cpp b/bolt/lib/Core/DIEBuilder.cpp index 7ce55f9165136..5b628f67c2b9b 100644 --- a/bolt/lib/Core/DIEBuilder.cpp +++ b/bolt/lib/Core/DIEBuilder.cpp @@ -137,7 +137,7 @@ void DIEBuilder::updateReferences() { DIEInteger(NewAddr)); } - // Handling referenes in location expressions. + // Handling references in location expressions. for (LocWithReference &LocExpr : getState().LocWithReferencesToProcess) { SmallVector Buffer; DataExtractor Data(StringRef((const char *)LocExpr.BlockData.data(), @@ -336,7 +336,7 @@ void DIEBuilder::buildCompileUnits(const bool Init) { registerUnit(*DU, false); } - // Using DULIst since it can be modified by cross CU refrence resolution. + // Using DULIst since it can be modified by cross CU reference resolution. for (DWARFUnit *DU : getState().DUList) { if (DU->isTypeUnit()) continue; @@ -508,7 +508,7 @@ void DIEBuilder::finish() { UnitStartOffset += CurUnitInfo.UnitLength; }; // Computing offsets for .debug_types section. - // It's processed first when CU is registered so will be at the begginnig of + // It's processed first when CU is registered so will be at the beginning of // the vector. uint64_t TypeUnitStartOffset = 0; for (DWARFUnit *CU : getState().DUList) { diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp index e05f28f08572c..24a4c852e9d7e 100644 --- a/bolt/lib/Core/DebugData.cpp +++ b/bolt/lib/Core/DebugData.cpp @@ -876,7 +876,7 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit, DIEValue StrListBaseAttrInfo = Die.findAttribute(dwarf::DW_AT_str_offsets_base); auto RetVal = ProcessedBaseOffsets.find(*Val); - // Handling re-use of str-offsets section. + // Handling reuse of str-offsets section. if (RetVal == ProcessedBaseOffsets.end() || StrOffsetSectionWasModified) { initialize(Unit); // Update String Offsets that were modified. @@ -1167,7 +1167,7 @@ void DwarfLineTable::emitCU(MCStreamer *MCOS, MCDwarfLineTableParams Params, // For functions that we do not modify we output them as raw data. // Re-constructing .debug_line_str so that offsets are correct for those // debug line tables. -// Bonus is that when we output a final binary we can re-use .debug_line_str +// Bonus is that when we output a final binary we can reuse .debug_line_str // section. So we don't have to do the SHF_ALLOC trick we did with // .debug_line. static void parseAndPopulateDebugLineStr(BinarySection &LineStrSection, diff --git a/bolt/lib/Core/DebugNames.cpp b/bolt/lib/Core/DebugNames.cpp index a9d98a6ba879b..6be2c5aa4e6c1 100644 --- a/bolt/lib/Core/DebugNames.cpp +++ b/bolt/lib/Core/DebugNames.cpp @@ -55,7 +55,7 @@ DWARF5AcceleratorTable::DWARF5AcceleratorTable( llvm::hash_value(llvm::StringRef(CStr)), StrOffset); if (!R.second) BC.errs() - << "BOLT-WARNING: [internal-dwarf-error]: collision occured on " + << "BOLT-WARNING: [internal-dwarf-error]: collision occurred on " << CStr << " at offset : 0x" << Twine::utohexstr(StrOffset) << ". Previous string offset is: 0x" << Twine::utohexstr(R.first->second) << ".\n"; @@ -86,7 +86,7 @@ void DWARF5AcceleratorTable::addUnit(DWARFUnit &Unit, if (Unit.isTypeUnit()) { if (DWOID) { // We adding an entry for a DWO TU. The DWO CU might not have any entries, - // so need to add it to the list pre-emptively. + // so need to add it to the list preemptively. auto Iter = CUOffsetsToPatch.insert({*DWOID, CUList.size()}); if (Iter.second) CUList.push_back(BADCUOFFSET); diff --git a/bolt/lib/Passes/Aligner.cpp b/bolt/lib/Passes/Aligner.cpp index c3ddedaaa1466..5d21bdb3f154a 100644 --- a/bolt/lib/Passes/Aligner.cpp +++ b/bolt/lib/Passes/Aligner.cpp @@ -60,7 +60,7 @@ namespace llvm { namespace bolt { // Align function to the specified byte-boundary (typically, 64) offsetting -// the fuction by not more than the corresponding value +// the function by not more than the corresponding value static void alignMaxBytes(BinaryFunction &Function) { Function.setAlignment(opts::AlignFunctions); Function.setMaxAlignmentBytes(opts::AlignFunctionsMaxBytes); @@ -68,7 +68,7 @@ static void alignMaxBytes(BinaryFunction &Function) { } // Align function to the specified byte-boundary (typically, 64) offsetting -// the fuction by not more than the minimum over +// the function by not more than the minimum over // -- the size of the function // -- the specified number of bytes static void alignCompact(BinaryFunction &Function, diff --git a/bolt/lib/Passes/FrameAnalysis.cpp b/bolt/lib/Passes/FrameAnalysis.cpp index f568039bbf163..0b26da3371234 100644 --- a/bolt/lib/Passes/FrameAnalysis.cpp +++ b/bolt/lib/Passes/FrameAnalysis.cpp @@ -198,7 +198,7 @@ class FrameAccessAnalysis { if (CFIStack.empty()) dbgs() << "Assertion is about to fail: " << BF.getPrintName() << "\n"; assert(!CFIStack.empty() && "Corrupt CFI stack"); - std::pair &Elem = CFIStack.top(); + std::pair Elem = CFIStack.top(); CFIStack.pop(); CfaOffset = Elem.first; CfaReg = Elem.second; diff --git a/bolt/lib/Passes/RegReAssign.cpp b/bolt/lib/Passes/RegReAssign.cpp index 60349f18b11d3..0859cd244ce40 100644 --- a/bolt/lib/Passes/RegReAssign.cpp +++ b/bolt/lib/Passes/RegReAssign.cpp @@ -145,7 +145,7 @@ void RegReAssign::rankRegisters(BinaryFunction &Function) { const bool CannotUseREX = BC.MIB->cannotUseREX(Inst); const MCInstrDesc &Desc = BC.MII->get(Inst.getOpcode()); - // Disallow substituitions involving regs in implicit uses lists + // Disallow substitutions involving regs in implicit uses lists for (MCPhysReg ImplicitUse : Desc.implicit_uses()) { const size_t RegEC = BC.MIB->getAliases(ImplicitUse, false).find_first(); @@ -153,7 +153,7 @@ void RegReAssign::rankRegisters(BinaryFunction &Function) { std::numeric_limits::min(); } - // Disallow substituitions involving regs in implicit defs lists + // Disallow substitutions involving regs in implicit defs lists for (MCPhysReg ImplicitDef : Desc.implicit_defs()) { const size_t RegEC = BC.MIB->getAliases(ImplicitDef, false).find_first(); @@ -174,7 +174,7 @@ void RegReAssign::rankRegisters(BinaryFunction &Function) { if (RegEC == 0) continue; - // Disallow substituitions involving regs in instrs that cannot use REX + // Disallow substitutions involving regs in instrs that cannot use REX // The relationship of X86 registers is shown in the diagram. BL and BH // do not have a direct alias relationship. However, if the BH register // cannot be swapped, then the BX/EBX/RBX registers cannot be swapped as diff --git a/bolt/lib/Passes/ShrinkWrapping.cpp b/bolt/lib/Passes/ShrinkWrapping.cpp index 4ea60f388e2fa..fe342ccd38a67 100644 --- a/bolt/lib/Passes/ShrinkWrapping.cpp +++ b/bolt/lib/Passes/ShrinkWrapping.cpp @@ -402,7 +402,7 @@ void StackLayoutModifier::classifyCFIs() { break; case MCCFIInstruction::OpRestoreState: { assert(!CFIStack.empty() && "Corrupt CFI stack"); - std::pair &Elem = CFIStack.top(); + std::pair Elem = CFIStack.top(); CFIStack.pop(); CfaOffset = Elem.first; CfaReg = Elem.second; diff --git a/bolt/lib/Passes/SplitFunctions.cpp b/bolt/lib/Passes/SplitFunctions.cpp index eab669b32b71e..66a373ad2de72 100644 --- a/bolt/lib/Passes/SplitFunctions.cpp +++ b/bolt/lib/Passes/SplitFunctions.cpp @@ -386,7 +386,7 @@ struct SplitCacheDirected final : public SplitStrategy { } /// Compute sum of scores over jumps within \p BlockOrder given \p SplitIndex. - /// Increament Score.LocalScore in place by the sum. + /// Increment Score.LocalScore in place by the sum. void computeJumpScore(const BasicBlockOrder &BlockOrder, const size_t SplitIndex, SplitScore &Score) { @@ -413,7 +413,7 @@ struct SplitCacheDirected final : public SplitStrategy { } /// Compute sum of scores over calls originated in the current function - /// given \p SplitIndex. Increament Score.LocalScore in place by the sum. + /// given \p SplitIndex. Increment Score.LocalScore in place by the sum. void computeLocalCallScore(const BasicBlockOrder &BlockOrder, const size_t SplitIndex, SplitScore &Score) { if (opts::CallScale == 0) @@ -455,7 +455,7 @@ struct SplitCacheDirected final : public SplitStrategy { } /// Compute sum of splitting scores for cover calls of the input function. - /// Increament Score.CoverCallScore in place by the sum. + /// Increment Score.CoverCallScore in place by the sum. void computeCoverCallScore(const BasicBlockOrder &BlockOrder, const size_t SplitIndex, const std::vector &CoverCalls, @@ -467,7 +467,7 @@ struct SplitCacheDirected final : public SplitStrategy { assert(CI.Length >= Score.HotSizeReduction && "Length of cover calls must exceed reduced size of hot fragment."); // Compute the new length of the call, which is shorter than the original - // one by the size of the splitted fragment minus the total size increase. + // one by the size of the split fragment minus the total size increase. const size_t NewCallLength = CI.Length - Score.HotSizeReduction; Score.CoverCallScore += computeCallScore(CI.Count, NewCallLength); } @@ -502,12 +502,12 @@ struct SplitCacheDirected final : public SplitStrategy { // First part of LocalScore is the sum over call edges originated in the // input function. These edges can get shorter or longer depending on - // SplitIndex. Score.LocalScore is increamented in place. + // SplitIndex. Score.LocalScore is incremented in place. computeLocalCallScore(BlockOrder, SplitIndex, Score); // Second part of LocalScore is the sum over jump edges with src basic block // and dst basic block in the current function. Score.LocalScore is - // increamented in place. + // incremented in place. computeJumpScore(BlockOrder, SplitIndex, Score); // Compute CoverCallScore and store in Score in place. diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp index afe24216d7f5d..277d4bb5e7282 100644 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -907,7 +907,7 @@ ErrorOr DataReader::parseHexField(char EndChar, bool EndNl) { StringRef NumStr = NumStrRes.get(); uint64_t Num; if (NumStr.getAsInteger(16, Num)) { - reportError("expected hexidecimal number"); + reportError("expected hexadecimal number"); Diag << "Found: " << NumStr << "\n"; return make_error_code(llvm::errc::io_error); } diff --git a/bolt/lib/Rewrite/BuildIDRewriter.cpp b/bolt/lib/Rewrite/BuildIDRewriter.cpp index d50416fb80c6c..706a3d0d92d56 100644 --- a/bolt/lib/Rewrite/BuildIDRewriter.cpp +++ b/bolt/lib/Rewrite/BuildIDRewriter.cpp @@ -48,7 +48,7 @@ class BuildIDRewriter final : public MetadataRewriter { }; Error BuildIDRewriter::sectionInitializer() { - // Typically, build ID will reside in .note.gnu.build-id section. Howerver, + // Typically, build ID will reside in .note.gnu.build-id section. However, // a linker script can change the section name and such is the case with // the Linux kernel. Hence, we iterate over all note sections. for (BinarySection &NoteSection : BC.sections()) { diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 7366d2aca35ea..a7a4b664693fc 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -1723,7 +1723,7 @@ StringRef getSectionName(const SectionRef &Section) { return Name; } -// Exctracts an appropriate slice if input is DWP. +// Extracts an appropriate slice if input is DWP. // Applies patches or overwrites the section. std::optional updateDebugData( DWARFContext &DWCtx, StringRef SectionName, StringRef SectionContents, @@ -1759,7 +1759,7 @@ std::optional updateDebugData( auto Iter = OverridenSections.find(Kind); if (Iter == OverridenSections.end()) { errs() - << "BOLT-WARNING: [internal-dwarf-error]: Could not find overriden " + << "BOLT-WARNING: [internal-dwarf-error]: Could not find overridden " "section for: " << Twine::utohexstr(DWOId) << ".\n"; return std::nullopt; @@ -1991,7 +1991,7 @@ void DWARFRewriter::convertToRangesPatchDebugInfo( } } - // HighPC was conveted into DW_AT_ranges. + // HighPC was converted into DW_AT_ranges. // For DWARF5 we only access ranges through index. DIEBldr.replaceValue(&Die, HighPCAttrInfo.getAttribute(), dwarf::DW_AT_ranges, diff --git a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp index ee021fee3cea5..947d8992890d4 100644 --- a/bolt/lib/Rewrite/PseudoProbeRewriter.cpp +++ b/bolt/lib/Rewrite/PseudoProbeRewriter.cpp @@ -308,7 +308,7 @@ void PseudoProbeRewriter::encodePseudoProbes() { Contents.append(OSE.str().begin(), OSE.str().end()); }; - // Emit indiviual pseudo probes in a inline tree node + // Emit individual pseudo probes in a inline tree node // Probe index, type, attribute, address type and address are encoded // Address of the first probe is absolute. // Other probes' address are represented by delta diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index c428828956ca0..958016384cd9c 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1087,7 +1087,7 @@ void RewriteInstance::discoverFileObjects() { if (SymbolAddress == Section->getAddress() + Section->getSize()) { assert(SymbolSize == 0 && - "unexpect non-zero sized symbol at end of section"); + "unexpected non-zero sized symbol at end of section"); LLVM_DEBUG( dbgs() << "BOLT-DEBUG: rejecting as symbol points to end of its section\n"); @@ -1514,6 +1514,12 @@ void RewriteInstance::registerFragments() { } if (BD) { BinaryFunction *BF = BC->getFunctionForSymbol(BD->getSymbol()); + if (BF == &Function) { + BC->errs() + << "BOLT-WARNING: fragment maps to the same function as parent: " + << Function << '\n'; + continue; + } if (BF) { BC->registerFragment(Function, *BF); continue; @@ -2434,7 +2440,7 @@ void RewriteInstance::processDynamicRelocations() { } // The rest of dynamic relocations - DT_RELA. - // The static executable might have .rela.dyn secion and not have PT_DYNAMIC + // The static executable might have .rela.dyn section and not have PT_DYNAMIC if (!DynamicRelocationsSize && BC->IsStaticExecutable) { ErrorOr DynamicRelSectionOrErr = BC->getUniqueSectionByName(getRelaDynSectionName()); @@ -4005,10 +4011,12 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) { BC->outs() << '\n'; AllocationDone = true; } else { - BC->errs() << "BOLT-WARNING: original .text too small to fit the new code" - << " using 0x" << Twine::utohexstr(opts::AlignText) - << " alignment. " << CodeSize << " bytes needed, have " - << BC->OldTextSectionSize << " bytes available.\n"; + BC->errs() << "BOLT-WARNING: --use-old-text failed. The original .text " + "too small to fit the new code using 0x" + << Twine::utohexstr(opts::AlignText) << " alignment. " + << CodeSize << " bytes needed, have " << BC->OldTextSectionSize + << " bytes available. Rebuilding without --use-old-text may " + "produce a smaller binary\n"; opts::UseOldText = false; } } @@ -5009,7 +5017,7 @@ void RewriteInstance::updateELFSymbolTable( if (!Section) return false; - // Remove the section symbol iif the corresponding section was stripped. + // Remove the section symbol if the corresponding section was stripped. if (Symbol.getType() == ELF::STT_SECTION) { if (!getNewSectionIndex(Symbol.st_shndx)) return true; diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp index df4f42128605e..6954cb295e86a 100644 --- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp +++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp @@ -1296,7 +1296,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder { AArch64_AM::ShiftExtendType ExtendType = AArch64_AM::getArithExtendType(OperandExtension); if (ShiftVal != 2) { - // TODO: Handle the patten where ShiftVal != 2. + // TODO: Handle the pattern where ShiftVal != 2. // The following code sequence below has no shift amount, // the range could be 0 to 4. // The pattern comes from libc, it occurs when the binary is static. @@ -1626,7 +1626,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder { int getUncondBranchEncodingSize() const override { return 28; } // This helper function creates the snippet of code that compares a register - // RegNo with an immedaite Imm, and jumps to Target if they are equal. + // RegNo with an immediate Imm, and jumps to Target if they are equal. // cmp RegNo, #Imm // b.eq Target // where cmp is an alias for subs, which results in the code below: @@ -1648,7 +1648,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder { } // This helper function creates the snippet of code that compares a register - // RegNo with an immedaite Imm, and jumps to Target if they are not equal. + // RegNo with an immediate Imm, and jumps to Target if they are not equal. // cmp RegNo, #Imm // b.ne Target // where cmp is an alias for subs, which results in the code below: diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp index 9026a9df7b5c2..5fca5e813515f 100644 --- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp +++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp @@ -2715,7 +2715,7 @@ class X86MCPlusBuilder : public MCPlusBuilder { bool FoundOne = false; - // Iterate only through src operands that arent also dest operands + // Iterate only through src operands that aren't also dest operands for (unsigned Index = InstDesc.getNumDefs() + (HasLHS ? 1 : 0), E = InstDesc.getNumOperands(); Index != E; ++Index) { diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp index 095612ac3a4ac..5be04d2ceea94 100644 --- a/bolt/lib/Utils/CommandLineOpts.cpp +++ b/bolt/lib/Utils/CommandLineOpts.cpp @@ -285,7 +285,7 @@ cl::opt TimeRewrite("time-rewrite", cl::opt UseOldText( "use-old-text", - cl::desc("re-use space in old .text if possible (relocation mode)"), + cl::desc("reuse space in old .text if possible (relocation mode)"), cl::cat(BoltCategory)); cl::opt UpdateDebugSections( diff --git a/bolt/runtime/hugify.cpp b/bolt/runtime/hugify.cpp index 672b04247dfa4..de896307f24fc 100644 --- a/bolt/runtime/hugify.cpp +++ b/bolt/runtime/hugify.cpp @@ -24,7 +24,7 @@ {} #endif -// Function constains trampoline to _start, +// Function constrains trampoline to _start, // so we can resume regular execution of the function that we hooked. extern void __bolt_hugify_start_program(); diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp index 1f54a500dbf98..f586db2b0f9ba 100644 --- a/bolt/runtime/instr.cpp +++ b/bolt/runtime/instr.cpp @@ -214,7 +214,7 @@ class BumpPtrAllocator { /// __bolt_instr_setup, our initialization routine. BumpPtrAllocator *GlobalAlloc; -// Base address which we substract from recorded PC values when searching for +// Base address which we subtract from recorded PC values when searching for // indirect call description entries. Needed because indCall descriptions are // mapped read-only and contain static addresses. Initialized in // __bolt_instr_setup. @@ -261,7 +261,7 @@ struct SimpleHashTableEntryBase { // Currently we have to do it the ugly way because // we want every message to be printed atomically via a single call to // __write. If we use reportNumber() and others nultiple times, we'll get - // garbage in mulithreaded environment + // garbage in multithreaded environment char Buf[BufSize]; char *Ptr = Buf; Ptr = intToStr(Ptr, __getpid(), 10); @@ -1585,7 +1585,7 @@ __bolt_instr_data_dump(int FD, const char *LibPath = nullptr, /// at user-specified intervals void watchProcess() { timespec ts, rem; - uint64_t Ellapsed = 0ull; + uint64_t Elapsed = 0ull; int FD = openProfile(); uint64_t ppid; if (__bolt_instr_wait_forks) { @@ -1615,10 +1615,10 @@ void watchProcess() { break; } - if (++Ellapsed < __bolt_instr_sleep_time) + if (++Elapsed < __bolt_instr_sleep_time) continue; - Ellapsed = 0; + Elapsed = 0; __bolt_instr_data_dump(FD); if (__bolt_instr_no_counters_clear == false) __bolt_instr_clear_counters(); diff --git a/bolt/runtime/sys_aarch64.h b/bolt/runtime/sys_aarch64.h index 77c9cfcc99f98..b1d04f9d558e0 100644 --- a/bolt/runtime/sys_aarch64.h +++ b/bolt/runtime/sys_aarch64.h @@ -41,7 +41,7 @@ // Anonymous namespace covering everything but our library entry point namespace { -// Get the difference between runtime addrress of .text section and +// Get the difference between runtime address of .text section and // static address in section header table. Can be extracted from arbitrary // pc value recorded at runtime to get the corresponding static address, which // in turn can be used to search for indirect call description. Needed because diff --git a/bolt/runtime/sys_riscv64.h b/bolt/runtime/sys_riscv64.h index 00a21e4945f0f..442fa2e018494 100644 --- a/bolt/runtime/sys_riscv64.h +++ b/bolt/runtime/sys_riscv64.h @@ -105,7 +105,7 @@ // Anonymous namespace covering everything but our library entry point namespace { -// Get the difference between runtime addrress of .text section and +// Get the difference between runtime address of .text section and // static address in section header table. Can be extracted from arbitrary // pc value recorded at runtime to get the corresponding static address, which // in turn can be used to search for indirect call description. Needed because diff --git a/bolt/runtime/sys_x86_64.h b/bolt/runtime/sys_x86_64.h index ca2c69326a14f..933e939012481 100644 --- a/bolt/runtime/sys_x86_64.h +++ b/bolt/runtime/sys_x86_64.h @@ -40,7 +40,7 @@ namespace { -// Get the difference between runtime addrress of .text section and +// Get the difference between runtime address of .text section and // static address in section header table. Can be extracted from arbitrary // pc value recorded at runtime to get the corresponding static address, which // in turn can be used to search for indirect call description. Needed because @@ -171,8 +171,9 @@ uint64_t __exit(uint64_t code) { #if !defined(__APPLE__) // We use a stack-allocated buffer for string manipulation in many pieces of // this code, including the code that prints each line of the fdata file. This -// buffer needs to accomodate large function names, but shouldn't be arbitrarily -// large (dynamically allocated) for simplicity of our memory space usage. +// buffer needs to accommodate large function names, but shouldn't be +// arbitrarily large (dynamically allocated) for simplicity of our memory space +// usage. // Declare some syscall wrappers we use throughout this code to avoid linking // against system libc. diff --git a/bolt/test/AArch64/constant-island-alignment.s b/bolt/test/AArch64/constant-island-alignment.s index 957c4705f5eec..99fe7333e2dba 100644 --- a/bolt/test/AArch64/constant-island-alignment.s +++ b/bolt/test/AArch64/constant-island-alignment.s @@ -3,7 +3,7 @@ # RUN: split-file %s %t // For the first test case, in case the nop before .Lci will be removed -// the pointer to exit function won't be alinged and the test will fail. +// the pointer to exit function won't be aligned and the test will fail. # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \ # RUN: %t/xword_align.s -o %t_xa.o diff --git a/bolt/test/AArch64/ifunc.test b/bolt/test/AArch64/ifunc.test index 3da42c67c5a0a..15ecc3503f22f 100644 --- a/bolt/test/AArch64/ifunc.test +++ b/bolt/test/AArch64/ifunc.test @@ -9,7 +9,7 @@ // RUN: FileCheck --check-prefix=REL_CHECK %s // Non-pie static executable doesn't generate PT_DYNAMIC, check relocation -// is readed successfully and IPLT trampoline has been identified by bolt. +// is read successfully and IPLT trampoline has been identified by bolt. // RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -no-pie \ // RUN: -o %t.O3_nopie.exe -Wl,-q // RUN: llvm-readelf -l %t.O3_nopie.exe | \ diff --git a/bolt/test/X86/cdsplit-call-scale.s b/bolt/test/X86/cdsplit-call-scale.s index 66f30036de8c1..caa11b6feb6c4 100644 --- a/bolt/test/X86/cdsplit-call-scale.s +++ b/bolt/test/X86/cdsplit-call-scale.s @@ -1,8 +1,8 @@ ## Test the control of aggressiveness of 3-way splitting by -call-scale. -## When -call-scale=0.0, the tested function is 2-way splitted. -## When -call-scale=1.0, the tested function is 3-way splitted with 5 blocks +## When -call-scale=0.0, the tested function is 2-way split. +## When -call-scale=1.0, the tested function is 3-way split with 5 blocks ## in warm because of the increased benefit of shortening the call edges. -## When -call-scale=1000.0, the tested function is still 3-way splitted with +## When -call-scale=1000.0, the tested function is still 3-way split with ## 5 blocks in warm because cdsplit does not allow hot-warm splitting to break ## a fall through branch from a basic block to its most likely successor. diff --git a/bolt/test/X86/dwarf5-two-cu-str-offset-table.test b/bolt/test/X86/dwarf5-two-cu-str-offset-table.test index e59664e3281a1..488635b582d0d 100644 --- a/bolt/test/X86/dwarf5-two-cu-str-offset-table.test +++ b/bolt/test/X86/dwarf5-two-cu-str-offset-table.test @@ -8,7 +8,7 @@ # RUN: llvm-dwarfdump --show-form --verbose --debug-str-offsets %t.bolt >> %t.txt # RUN: cat %t.txt | FileCheck --check-prefix=CHECK %s -## This test checks we correclty re-renerate .debug_str_offsets. +## This test checks we correctly re-renerate .debug_str_offsets. # CHECK: .debug_str_offsets contents # CHECK-NEXT: 0x00000000: Contribution size = 52, Format = DWARF32, Version = 5 diff --git a/bolt/test/X86/dwarf5-type-unit-no-cu-str-offset-table.test b/bolt/test/X86/dwarf5-type-unit-no-cu-str-offset-table.test index dc6255ff8c7bc..0cb62ed21abd1 100644 --- a/bolt/test/X86/dwarf5-type-unit-no-cu-str-offset-table.test +++ b/bolt/test/X86/dwarf5-type-unit-no-cu-str-offset-table.test @@ -7,7 +7,7 @@ # RUN: llvm-dwarfdump --show-form --verbose --debug-str-offsets %t.exe | FileCheck -check-prefix=PRE-BOLT %s # RUN: llvm-dwarfdump --show-form --verbose --debug-str-offsets %t.bolt | FileCheck -check-prefix=POST-BOLT %s -## This test checks we correclty re-generate .debug_str_offsets when there are type units that have an offset not shared with CU. +## This test checks we correctly re-generate .debug_str_offsets when there are type units that have an offset not shared with CU. # PRE-BOLT: .debug_str_offsets contents # PRE-BOLT-NEXT: Contribution size = 24, Format = DWARF32, Version = 5 diff --git a/bolt/test/X86/fragment-alias.s b/bolt/test/X86/fragment-alias.s new file mode 100644 index 0000000000000..3392dd564f417 --- /dev/null +++ b/bolt/test/X86/fragment-alias.s @@ -0,0 +1,13 @@ +## This test reproduces the issue where a fragment has the same address as +## parent function. +# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o +# RUN: %clang %cflags %t.o -o %t +# RUN: llvm-bolt %t -o %t.out 2>&1 | FileCheck %s +# CHECK: BOLT-WARNING: fragment maps to the same function as parent: main/1(*2) +.type main, @function +.type main.cold, @function +main.cold: +main: + ret +.size main, .-main +.size main.cold, .-main.cold diff --git a/bolt/test/X86/jt-symbol-disambiguation-3.s b/bolt/test/X86/jt-symbol-disambiguation-3.s index 22b34cef1bc4d..c06fd3bb69894 100644 --- a/bolt/test/X86/jt-symbol-disambiguation-3.s +++ b/bolt/test/X86/jt-symbol-disambiguation-3.s @@ -1,6 +1,6 @@ ## In this test case, we reproduce the behavior seen in gcc where the ## base address of a jump table is decremented by some number and ends up -## at the exact addess of a jump table from another function. After +## at the exact address of a jump table from another function. After ## linking, the instruction references another jump table and that ## confuses BOLT. ## We repro here the following issue: @@ -28,7 +28,7 @@ # ---- # Func foo contains a jump table whose start is colocated with a # jump table reference in another function. However, the other function -# does not use the first entries of it and is merely doing arithmetics +# does not use the first entries of it and is merely doing arithmetic # to save the creation of unused first entries. # ---- .globl foo diff --git a/bolt/test/X86/split-landing-pad.s b/bolt/test/X86/split-landing-pad.s index 681f14f1e533e..149193dbe5188 100644 --- a/bolt/test/X86/split-landing-pad.s +++ b/bolt/test/X86/split-landing-pad.s @@ -1,5 +1,5 @@ ## This test reproduces the case where C++ exception handling is used and split -## function optimization is enabled. In particular, function foo is splitted +## function optimization is enabled. In particular, function foo is split ## to two fragments: ## foo: contains 2 try blocks, which invokes bar to throw exception ## foo.cold.1: contains 2 corresponding catch blocks (landing pad) diff --git a/bolt/test/perf2bolt/AArch64/perf2bolt-spe.test b/bolt/test/perf2bolt/AArch64/perf2bolt-spe.test index 91f5c857fbab0..1f44f7510a9fb 100644 --- a/bolt/test/perf2bolt/AArch64/perf2bolt-spe.test +++ b/bolt/test/perf2bolt/AArch64/perf2bolt-spe.test @@ -6,7 +6,6 @@ RUN: %clang %cflags %p/../../Inputs/asm_foo.s %p/../../Inputs/asm_main.c -o %t.e RUN: perf record -e cycles -q -o %t.perf.data -- %t.exe 2> /dev/null -RUN: (perf2bolt -p %t.perf.data -o %t.perf.boltdata --spe %t.exe 2> /dev/null; exit 0) | FileCheck %s --check-prefix=CHECK-SPE-LBR +RUN: perf2bolt -p %t.perf.data -o %t.perf.boltdata --spe %t.exe | FileCheck %s --check-prefix=CHECK-SPE-LBR CHECK-SPE-LBR: PERF2BOLT: parse SPE branch events in LBR-format - diff --git a/bolt/test/runtime/X86/asm-dump.c b/bolt/test/runtime/X86/asm-dump.c index 7656fda44d8d4..fa0de9b72fb64 100644 --- a/bolt/test/runtime/X86/asm-dump.c +++ b/bolt/test/runtime/X86/asm-dump.c @@ -30,7 +30,7 @@ * Reconstruct fdata * RUN: link_fdata %t/main.s %t.o %t.fdata.reconst * - * XXX: reenable once dumping data is supported + * XXX: re-enable once dumping data is supported * Check if reoptimized file produces the same results * dontrun: %t.exe.reopt > %t.result.reopt * dontrun: cmp %t.result %t.result.reopt diff --git a/bolt/test/runtime/wait_file.sh b/bolt/test/runtime/wait_file.sh index 42d4c5b29e795..73464764249d5 100644 --- a/bolt/test/runtime/wait_file.sh +++ b/bolt/test/runtime/wait_file.sh @@ -12,7 +12,7 @@ check_file() { fuser -s "$file" local ret=$? - if [ $ret -eq 1 ]; then # noone has file open + if [ $ret -eq 1 ]; then # no one has file open return 0 fi if [ $ret -eq 0 ]; then # file open by some processes diff --git a/bolt/utils/bughunter.sh b/bolt/utils/bughunter.sh index c5dddc41fb41f..d5ce0592708e2 100755 --- a/bolt/utils/bughunter.sh +++ b/bolt/utils/bughunter.sh @@ -28,7 +28,7 @@ # # TIMEOUT_OR_CMD - optional timeout or command on optimized binary command # if the value is a number with an optional trailing letter -# [smhd] it is considered a paramter to "timeout", +# [smhd] it is considered a parameter to "timeout", # otherwise it's a shell command that wraps the optimized # binary command. # diff --git a/bolt/utils/docker/Dockerfile b/bolt/utils/docker/Dockerfile index c58e1a533df94..86d1be2141655 100644 --- a/bolt/utils/docker/Dockerfile +++ b/bolt/utils/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:24.04 AS builder +FROM docker.io/library/ubuntu:24.04 AS builder ARG DEBIAN_FRONTEND=noninteractive ENV TZ=UTC @@ -25,6 +25,6 @@ RUN mkdir build && \ ninja check-bolt && \ ninja install-llvm-bolt install-merge-fdata install-bolt_rt -FROM ubuntu:24.04 +FROM docker.io/library/ubuntu:24.04 COPY --from=builder /home/bolt/install /usr/local diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index b37dc272ea156..b4b9322b0500a 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -46,7 +46,13 @@ class MustacheHTMLGenerator : public Generator { const ClangDocContext &CDCtx) override; }; -class MustacheTemplateFile : public Template { +class MustacheTemplateFile { + BumpPtrAllocator Allocator; + StringSaver Saver; + MustacheContext Ctx; + Template T; + std::unique_ptr Buffer; + public: static Expected> createMustacheFile(StringRef FileName) { @@ -54,10 +60,8 @@ class MustacheTemplateFile : public Template { MemoryBuffer::getFile(FileName); if (auto EC = BufferOrError.getError()) return createFileOpenError(FileName, EC); - - std::unique_ptr Buffer = std::move(BufferOrError.get()); - StringRef FileContent = Buffer->getBuffer(); - return std::make_unique(FileContent); + return std::make_unique( + std::move(BufferOrError.get())); } Error registerPartialFile(StringRef Name, StringRef FileName) { @@ -68,11 +72,15 @@ class MustacheTemplateFile : public Template { std::unique_ptr Buffer = std::move(BufferOrError.get()); StringRef FileContent = Buffer->getBuffer(); - registerPartial(Name.str(), FileContent.str()); + T.registerPartial(Name.str(), FileContent.str()); return Error::success(); } - MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {} + void render(json::Value &V, raw_ostream &OS) { T.render(V, OS); } + + MustacheTemplateFile(std::unique_ptr &&B) + : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx), + Buffer(std::move(B)) {} }; static std::unique_ptr NamespaceTemplate = nullptr; diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 26794a5e34d02..b17cc80bdba34 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -582,15 +582,22 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) { if (I->IT == InfoType::IT_record) { auto *RecordSymbolInfo = static_cast(I); FileName = RecordSymbolInfo->MangledName; - } else if (I->IT == InfoType::IT_namespace && I->Name != "") - // Serialize the global namespace as index.json + } else if (I->USR == GlobalNamespaceID) + FileName = "index"; + else if (I->IT == InfoType::IT_namespace) { + for (const auto &NS : I->Namespace) { + FileName += NS.Name; + FileName += "_"; + } + FileName += I->Name; + } else FileName = I->Name; - else - FileName = I->getFileBaseName(); sys::path::append(Path, FileName + ".json"); return FileName; } +// FIXME: Revert back to creating nested directories for namespaces instead of +// putting everything in a flat directory structure. Error JSONGenerator::generateDocs( StringRef RootDir, llvm::StringMap> Infos, const ClangDocContext &CDCtx) { diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index 2a75f89696b7d..d8c2b9c0a5842 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -30,6 +30,9 @@ namespace doc { // SHA1'd hash of a USR. using SymbolID = std::array; +constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + struct BaseRecordInfo; struct EnumInfo; struct FunctionInfo; diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp index 843368e723f1f..aaf0594a02dfc 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -40,8 +40,9 @@ SuspiciousIncludeCheck::SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), HeaderFileExtensions(Context->getHeaderFileExtensions()), - ImplementationFileExtensions(Context->getImplementationFileExtensions()) { -} + ImplementationFileExtensions(Context->getImplementationFileExtensions()), + IgnoredRegexString(Options.get("IgnoredRegex").value_or(StringRef{})), + IgnoredRegex(IgnoredRegexString) {} void SuspiciousIncludeCheck::registerPPCallbacks( const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { @@ -49,6 +50,11 @@ void SuspiciousIncludeCheck::registerPPCallbacks( ::std::make_unique(*this, SM, PP)); } +void SuspiciousIncludeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + if (!IgnoredRegexString.empty()) + Options.store(Opts, "IgnoredRegex", IgnoredRegexString); +} + void SuspiciousIncludePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, @@ -57,6 +63,9 @@ void SuspiciousIncludePPCallbacks::InclusionDirective( if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import) return; + if (!Check.IgnoredRegexString.empty() && Check.IgnoredRegex.match(FileName)) + return; + SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1); const std::optional IFE = diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h index 3aa9491ef0e3b..50fc34595b5d6 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h @@ -10,7 +10,6 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H #include "../ClangTidyCheck.h" -#include "../utils/FileExtensionsUtils.h" namespace clang::tidy::bugprone { @@ -28,9 +27,12 @@ class SuspiciousIncludeCheck : public ClangTidyCheck { SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context); void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override; + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; FileExtensionsSet HeaderFileExtensions; FileExtensionsSet ImplementationFileExtensions; + StringRef IgnoredRegexString; + llvm::Regex IgnoredRegex; }; } // namespace clang::tidy::bugprone diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp index ed595e1148dec..2545548df4f45 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -108,7 +108,7 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) { << MatchedDecl; if (*InitializationString != nullptr) Diagnostic << FixItHint::CreateInsertion( - utils::lexer::findNextTerminator(MatchedDecl->getLocation(), + utils::lexer::findNextTerminator(MatchedDecl->getEndLoc(), *Result.SourceManager, Result.Context->getLangOpts()), *InitializationString); diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt index c12c281bc5321..c7234098f094a 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt @@ -10,6 +10,7 @@ add_clang_library(clangTidyFuchsiaModule STATIC MultipleInheritanceCheck.cpp OverloadedOperatorCheck.cpp StaticallyConstructedObjectsCheck.cpp + TemporaryObjectsCheck.cpp TrailingReturnCheck.cpp VirtualInheritanceCheck.cpp diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index f280a1b07bf39..c62c43f0c42a3 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -15,6 +15,7 @@ #include "MultipleInheritanceCheck.h" #include "OverloadedOperatorCheck.h" #include "StaticallyConstructedObjectsCheck.h" +#include "TemporaryObjectsCheck.h" #include "TrailingReturnCheck.h" #include "VirtualInheritanceCheck.h" @@ -39,6 +40,8 @@ class FuchsiaModule : public ClangTidyModule { "fuchsia-overloaded-operator"); CheckFactories.registerCheck( "fuchsia-statically-constructed-objects"); + CheckFactories.registerCheck( + "fuchsia-temporary-objects"); CheckFactories.registerCheck( "fuchsia-trailing-return"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp similarity index 96% rename from clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp rename to clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp index 96a36cba827e6..7b910b1021979 100644 --- a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.cpp @@ -15,7 +15,7 @@ using namespace clang::ast_matchers; -namespace clang::tidy::zircon { +namespace clang::tidy::fuchsia { namespace { @@ -55,4 +55,4 @@ void TemporaryObjectsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "Names", utils::options::serializeStringList(Names)); } -} // namespace clang::tidy::zircon +} // namespace clang::tidy::fuchsia diff --git a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.h similarity index 76% rename from clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h rename to clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.h index ee96fa74affc6..805dae4d577d8 100644 --- a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.h +++ b/clang-tools-extra/clang-tidy/fuchsia/TemporaryObjectsCheck.h @@ -6,19 +6,19 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ZIRCON_TEMPORARYOBJECTSCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ZIRCON_TEMPORARYOBJECTSCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TEMPORARYOBJECTSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TEMPORARYOBJECTSCHECK_H #include "../ClangTidyCheck.h" #include "../utils/OptionsUtils.h" -namespace clang::tidy::zircon { +namespace clang::tidy::fuchsia { /// Construction of specific temporary objects in the Zircon kernel is /// discouraged. /// /// For the user-facing documentation see: -/// https://clang.llvm.org/extra/clang-tidy/checks/zircon/temporary-objects.html +/// https://clang.llvm.org/extra/clang-tidy/checks/fuchsia/temporary-objects.html class TemporaryObjectsCheck : public ClangTidyCheck { public: TemporaryObjectsCheck(StringRef Name, ClangTidyContext *Context) @@ -35,6 +35,6 @@ class TemporaryObjectsCheck : public ClangTidyCheck { std::vector Names; }; -} // namespace clang::tidy::zircon +} // namespace clang::tidy::fuchsia -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ZIRCON_TEMPORARYOBJECTSCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TEMPORARYOBJECTSCHECK_H diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp index b93f3d6a5a13b..8c25e928667df 100644 --- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp @@ -249,7 +249,8 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) { CheckValue(); if (WarnPointersAsPointers) { if (const auto *PT = dyn_cast(VT)) { - if (!PT->getPointeeType().isConstQualified()) + if (!PT->getPointeeType().isConstQualified() && + !PT->getPointeeType()->isFunctionType()) CheckPointee(); } if (const auto *AT = dyn_cast(VT)) { diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp index 9f4c215614287..1de9e136c5719 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -24,8 +24,9 @@ namespace { class IncludeModernizePPCallbacks : public PPCallbacks { public: explicit IncludeModernizePPCallbacks( - std::vector &IncludesToBeProcessed, LangOptions LangOpts, - const SourceManager &SM, bool CheckHeaderFile); + std::vector &IncludesToBeProcessed, + const LangOptions &LangOpts, const SourceManager &SM, + bool CheckHeaderFile); void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, @@ -37,8 +38,7 @@ class IncludeModernizePPCallbacks : public PPCallbacks { private: std::vector &IncludesToBeProcessed; - LangOptions LangOpts; - llvm::StringMap CStyledHeaderToCxx; + llvm::StringMap CStyledHeaderToCxx; llvm::StringSet<> DeleteHeaders; const SourceManager &SM; bool CheckHeaderFile; @@ -131,48 +131,35 @@ void DeprecatedHeadersCheck::check( } IncludeModernizePPCallbacks::IncludeModernizePPCallbacks( - std::vector &IncludesToBeProcessed, LangOptions LangOpts, - const SourceManager &SM, bool CheckHeaderFile) - : IncludesToBeProcessed(IncludesToBeProcessed), LangOpts(LangOpts), SM(SM), + std::vector &IncludesToBeProcessed, + const LangOptions &LangOpts, const SourceManager &SM, bool CheckHeaderFile) + : IncludesToBeProcessed(IncludesToBeProcessed), SM(SM), CheckHeaderFile(CheckHeaderFile) { - for (const auto &KeyValue : - std::vector>( - {{"assert.h", "cassert"}, - {"complex.h", "complex"}, - {"ctype.h", "cctype"}, - {"errno.h", "cerrno"}, - {"float.h", "cfloat"}, - {"limits.h", "climits"}, - {"locale.h", "clocale"}, - {"math.h", "cmath"}, - {"setjmp.h", "csetjmp"}, - {"signal.h", "csignal"}, - {"stdarg.h", "cstdarg"}, - {"stddef.h", "cstddef"}, - {"stdio.h", "cstdio"}, - {"stdlib.h", "cstdlib"}, - {"string.h", "cstring"}, - {"time.h", "ctime"}, - {"wchar.h", "cwchar"}, - {"wctype.h", "cwctype"}})) { - CStyledHeaderToCxx.insert(KeyValue); - } - // Add C++11 headers. - if (LangOpts.CPlusPlus11) { - for (const auto &KeyValue : - std::vector>( - {{"fenv.h", "cfenv"}, - {"stdint.h", "cstdint"}, - {"inttypes.h", "cinttypes"}, - {"tgmath.h", "ctgmath"}, - {"uchar.h", "cuchar"}})) { - CStyledHeaderToCxx.insert(KeyValue); - } - } - for (const auto &Key : - std::vector({"stdalign.h", "stdbool.h", "iso646.h"})) { - DeleteHeaders.insert(Key); - } + + static constexpr std::pair CXX98Headers[] = { + {"assert.h", "cassert"}, {"complex.h", "complex"}, + {"ctype.h", "cctype"}, {"errno.h", "cerrno"}, + {"float.h", "cfloat"}, {"limits.h", "climits"}, + {"locale.h", "clocale"}, {"math.h", "cmath"}, + {"setjmp.h", "csetjmp"}, {"signal.h", "csignal"}, + {"stdarg.h", "cstdarg"}, {"stddef.h", "cstddef"}, + {"stdio.h", "cstdio"}, {"stdlib.h", "cstdlib"}, + {"string.h", "cstring"}, {"time.h", "ctime"}, + {"wchar.h", "cwchar"}, {"wctype.h", "cwctype"}, + }; + CStyledHeaderToCxx.insert(std::begin(CXX98Headers), std::end(CXX98Headers)); + + static constexpr std::pair CXX11Headers[] = { + {"fenv.h", "cfenv"}, {"stdint.h", "cstdint"}, + {"inttypes.h", "cinttypes"}, {"tgmath.h", "ctgmath"}, + {"uchar.h", "cuchar"}, + }; + if (LangOpts.CPlusPlus11) + CStyledHeaderToCxx.insert(std::begin(CXX11Headers), std::end(CXX11Headers)); + + static constexpr StringRef HeadersToDelete[] = {"stdalign.h", "stdbool.h", + "iso646.h"}; + DeleteHeaders.insert_range(HeadersToDelete); } void IncludeModernizePPCallbacks::InclusionDirective( @@ -205,7 +192,7 @@ void IncludeModernizePPCallbacks::InclusionDirective( } else if (DeleteHeaders.contains(FileName)) { IncludesToBeProcessed.emplace_back( // NOLINTNEXTLINE(modernize-use-emplace) - false-positive - IncludeMarker{std::string{}, FileName, + IncludeMarker{StringRef{}, FileName, SourceRange{HashLoc, FilenameRange.getEnd()}, DiagLoc}); } } diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h index cbd1075497d8d..badb2b41f164f 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h @@ -44,7 +44,7 @@ class DeprecatedHeadersCheck : public ClangTidyCheck { void check(const ast_matchers::MatchFinder::MatchResult &Result) override; struct IncludeMarker { - std::string Replacement; + StringRef Replacement; StringRef FileName; SourceRange ReplacementRange; SourceLocation DiagLoc; diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp index f2bc6f10b9c58..4a586c8ff0ac9 100644 --- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp @@ -39,8 +39,11 @@ static FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, auto NewName = Decl->getName().str(); size_t Index = 0; if (Style == CategoryProperty) { - Index = Name.find_first_of('_') + 1; - NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower()); + size_t UnderScorePos = Name.find_first_of('_'); + if (UnderScorePos != llvm::StringRef::npos) { + Index = UnderScorePos + 1; + NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower()); + } } if (Index < Name.size()) { NewName[Index] = tolower(NewName[Index]); diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index 3fb856097a7e9..bfdf9cbd92d2b 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -89,7 +89,8 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag, const Expr *SubExpr = Cast->getSubExpr(); - bool NeedInnerParens = utils::fixit::areParensNeededForStatement(*SubExpr); + bool NeedInnerParens = + utils::fixit::areParensNeededForStatement(*SubExpr->IgnoreImpCasts()); bool NeedOuterParens = Parent != nullptr && utils::fixit::areParensNeededForStatement(*Parent); diff --git a/clang-tools-extra/clang-tidy/zircon/CMakeLists.txt b/clang-tools-extra/clang-tidy/zircon/CMakeLists.txt index e08fe80e730ac..bc4ab1f58c83d 100644 --- a/clang-tools-extra/clang-tidy/zircon/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/zircon/CMakeLists.txt @@ -4,11 +4,11 @@ set(LLVM_LINK_COMPONENTS ) add_clang_library(clangTidyZirconModule STATIC - TemporaryObjectsCheck.cpp ZirconTidyModule.cpp LINK_LIBS clangTidy + clangTidyFuchsiaModule clangTidyUtils DEPENDS diff --git a/clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp b/clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp index 86d7ce4e04e7b..30db5e251001f 100644 --- a/clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/zircon/ZirconTidyModule.cpp @@ -9,9 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "TemporaryObjectsCheck.h" - -using namespace clang::ast_matchers; +#include "../fuchsia/TemporaryObjectsCheck.h" namespace clang::tidy { namespace zircon { @@ -20,14 +18,14 @@ namespace zircon { class ZirconModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck( + CheckFactories.registerCheck( "zircon-temporary-objects"); } }; // Register the ZirconTidyModule using this statically initialized variable. static ClangTidyModuleRegistry::Add - X("zircon-module", "Adds Zircon kernel checks."); + X("zircon-module", "Adds Zircon kernel checks (deprecated in LLVM 24)."); } // namespace zircon // This anchor is used to force the linker to link in the generated object file diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index b445dcf2bbd2e..0f765e96fb152 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -81,7 +81,7 @@ CodeAction toCodeAction(const ClangdServer::CodeActionResult::Rename &R, const URIForFile &File) { CodeAction CA; CA.title = R.FixMessage; - CA.kind = std::string(CodeAction::REFACTOR_KIND); + CA.kind = std::string(CodeAction::QUICKFIX_KIND); CA.command.emplace(); CA.command->title = R.FixMessage; CA.command->command = std::string(ApplyRenameCommand); diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 8aae41420b83e..5d5388eeb8314 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -1040,16 +1040,11 @@ class ExplicitReferenceCollector if (auto *S = N.get()) return refInStmt(S, Resolver); if (auto *NNSL = N.get()) { + if (TypeLoc TL = NNSL->getAsTypeLoc()) + return refInTypeLoc(TL, Resolver); // (!) 'DeclRelation::Alias' ensures we do not lose namespace aliases. - NestedNameSpecifierLoc Qualifier; - SourceLocation NameLoc; - if (auto TL = NNSL->getAsTypeLoc()) { - Qualifier = TL.getPrefix(); - NameLoc = TL.getNonPrefixBeginLoc(); - } else { - Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix; - NameLoc = NNSL->getLocalBeginLoc(); - } + NestedNameSpecifierLoc Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix; + SourceLocation NameLoc = NNSL->getLocalBeginLoc(); return { ReferenceLoc{Qualifier, NameLoc, false, explicitReferenceTargets( diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index 138544dea99a1..acc8e87ed4764 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -1537,6 +1537,12 @@ markup::Document HoverInfo::presentDoxygen() const { SymbolDocCommentVisitor SymbolDoc(Documentation, CommentOpts); if (SymbolDoc.hasBriefCommand()) { + if (Kind != index::SymbolKind::Parameter && + Kind != index::SymbolKind::TemplateTypeParm) + // Only add a "Brief" heading if we are not documenting a parameter. + // Parameters only have a brief section and adding the brief header would + // be redundant. + Output.addHeading(3).appendText("Brief"); SymbolDoc.briefToMarkup(Output.addParagraph()); Output.addRuler(); } @@ -1550,7 +1556,7 @@ markup::Document HoverInfo::presentDoxygen() const { // Returns // `type` - description if (TemplateParameters && !TemplateParameters->empty()) { - Output.addParagraph().appendBoldText("Template Parameters:"); + Output.addHeading(3).appendText("Template Parameters"); markup::BulletList &L = Output.addBulletList(); for (const auto &Param : *TemplateParameters) { markup::Paragraph &P = L.addItem().addParagraph(); @@ -1564,7 +1570,7 @@ markup::Document HoverInfo::presentDoxygen() const { } if (Parameters && !Parameters->empty()) { - Output.addParagraph().appendBoldText("Parameters:"); + Output.addHeading(3).appendText("Parameters"); markup::BulletList &L = Output.addBulletList(); for (const auto &Param : *Parameters) { markup::Paragraph &P = L.addItem().addParagraph(); @@ -1583,7 +1589,7 @@ markup::Document HoverInfo::presentDoxygen() const { if (ReturnType && ((ReturnType->Type != "void" && !ReturnType->AKA.has_value()) || (ReturnType->AKA.has_value() && ReturnType->AKA != "void"))) { - Output.addParagraph().appendBoldText("Returns:"); + Output.addHeading(3).appendText("Returns"); markup::Paragraph &P = Output.addParagraph(); P.appendCode(llvm::to_string(*ReturnType)); @@ -1591,15 +1597,15 @@ markup::Document HoverInfo::presentDoxygen() const { P.appendText(" - "); SymbolDoc.returnToMarkup(P); } + + SymbolDoc.retvalsToMarkup(Output); Output.addRuler(); } - // add specially handled doxygen commands. - SymbolDoc.warningsToMarkup(Output); - SymbolDoc.notesToMarkup(Output); - - // add any other documentation. - SymbolDoc.docToMarkup(Output); + if (SymbolDoc.hasDetailedDoc()) { + Output.addHeading(3).appendText("Details"); + SymbolDoc.detailedDocToMarkup(Output); + } Output.addRuler(); diff --git a/clang-tools-extra/clangd/SymbolDocumentation.cpp b/clang-tools-extra/clangd/SymbolDocumentation.cpp index 9ae1ef3f828e0..a50d7a565b1bc 100644 --- a/clang-tools-extra/clangd/SymbolDocumentation.cpp +++ b/clang-tools-extra/clangd/SymbolDocumentation.cpp @@ -13,6 +13,7 @@ #include "clang/AST/CommentCommandTraits.h" #include "clang/AST/CommentVisitor.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" namespace clang { @@ -34,10 +35,20 @@ void commandToMarkup(markup::Paragraph &Out, StringRef Command, StringRef Args) { Out.appendBoldText(commandMarkerAsString(CommandMarker) + Command.str()); Out.appendSpace(); - if (!Args.empty()) { - Out.appendEmphasizedText(Args.str()); + if (!Args.empty()) + Out.appendCode(Args.str()); +} + +template std::string getArgText(const T *Command) { + std::string ArgText; + for (unsigned I = 0; I < Command->getNumArgs(); ++I) { + if (!ArgText.empty()) + ArgText += " "; + ArgText += Command->getArgText(I); } + return ArgText; } + } // namespace class ParagraphToMarkupDocument @@ -70,12 +81,7 @@ class ParagraphToMarkupDocument void visitInlineCommandComment(const comments::InlineCommandComment *C) { if (C->getNumArgs() > 0) { - std::string ArgText; - for (unsigned I = 0; I < C->getNumArgs(); ++I) { - if (!ArgText.empty()) - ArgText += " "; - ArgText += C->getArgText(I); - } + std::string ArgText = getArgText(C); switch (C->getRenderKind()) { case comments::InlineCommandRenderKind::Monospaced: @@ -158,10 +164,9 @@ class ParagraphToString void visitInlineCommandComment(const comments::InlineCommandComment *C) { Out << commandMarkerAsString(C->getCommandMarker()); Out << C->getCommandName(Traits); - if (C->getNumArgs() > 0) { - for (unsigned I = 0; I < C->getNumArgs(); ++I) - Out << " " << C->getArgText(I); - } + std::string ArgText = getArgText(C); + if (!ArgText.empty()) + Out << " " << ArgText; Out << " "; } @@ -210,16 +215,38 @@ class BlockCommentToMarkupDocument Traits) .visit(B->getParagraph()); break; + case comments::CommandTraits::KCI_note: + case comments::CommandTraits::KCI_warning: + commandToHeadedParagraph(B); + break; + case comments::CommandTraits::KCI_retval: { + // The \retval command describes the return value given as its single + // argument in the corresponding paragraph. + // Note: We know that we have exactly one argument but not if it has an + // associated paragraph. + auto &P = Out.addParagraph().appendCode(getArgText(B)); + if (B->getParagraph() && !B->getParagraph()->isWhitespace()) { + P.appendText(" - "); + ParagraphToMarkupDocument(P, Traits).visit(B->getParagraph()); + } + return; + } + case comments::CommandTraits::KCI_details: { + // The \details command is just used to separate the brief from the + // detailed description. This separation is already done in the + // SymbolDocCommentVisitor. Therefore we can omit the command itself + // here and just process the paragraph. + if (B->getParagraph() && !B->getParagraph()->isWhitespace()) { + ParagraphToMarkupDocument(Out.addParagraph(), Traits) + .visit(B->getParagraph()); + } + return; + } default: { // Some commands have arguments, like \throws. // The arguments are not part of the paragraph. // We need reconstruct them here. - std::string ArgText; - for (unsigned I = 0; I < B->getNumArgs(); ++I) { - if (!ArgText.empty()) - ArgText += " "; - ArgText += B->getArgText(I); - } + std::string ArgText = getArgText(B); auto &P = Out.addParagraph(); commandToMarkup(P, B->getCommandName(Traits), B->getCommandMarker(), ArgText); @@ -234,7 +261,53 @@ class BlockCommentToMarkupDocument } } + void visitCodeCommand(const comments::VerbatimBlockComment *VB) { + std::string CodeLang = ""; + auto *FirstLine = VB->child_begin(); + // The \\code command has an optional language argument. + // This argument is currently not parsed by the clang doxygen parser. + // Therefore we try to extract it from the first line of the verbatim + // block. + if (VB->getNumLines() > 0) { + if (const auto *Line = + cast(*FirstLine)) { + llvm::StringRef Text = Line->getText(); + // Language is a single word enclosed in {}. + if (llvm::none_of(Text, llvm::isSpace) && Text.consume_front("{") && + Text.consume_back("}")) { + // drop a potential . since this is not supported in Markdown + // fenced code blocks. + Text.consume_front("."); + // Language is alphanumeric or '+'. + CodeLang = Text.take_while([](char C) { + return llvm::isAlnum(C) || C == '+'; + }) + .str(); + // Skip the first line for the verbatim text. + ++FirstLine; + } + } + } + + std::string CodeBlockText; + + for (const auto *LI = FirstLine; LI != VB->child_end(); ++LI) { + if (const auto *Line = cast(*LI)) { + CodeBlockText += Line->getText().str() + "\n"; + } + } + + Out.addCodeBlock(CodeBlockText, CodeLang); + } + void visitVerbatimBlockComment(const comments::VerbatimBlockComment *VB) { + // The \\code command is a special verbatim block command which we handle + // separately. + if (VB->getCommandID() == comments::CommandTraits::KCI_code) { + visitCodeCommand(VB); + return; + } + commandToMarkup(Out.addParagraph(), VB->getCommandName(Traits), VB->getCommandMarker(), ""); @@ -262,8 +335,123 @@ class BlockCommentToMarkupDocument markup::Document &Out; const comments::CommandTraits &Traits; StringRef CommentEscapeMarker; + + /// Emphasize the given command in a paragraph. + /// Uses the command name with the first letter capitalized as the heading. + void commandToHeadedParagraph(const comments::BlockCommandComment *B) { + auto &P = Out.addParagraph(); + std::string Heading = B->getCommandName(Traits).slice(0, 1).upper() + + B->getCommandName(Traits).drop_front().str(); + P.appendBoldText(Heading + ":"); + P.appendText(" \n"); + ParagraphToMarkupDocument(P, Traits).visit(B->getParagraph()); + } }; +void SymbolDocCommentVisitor::preprocessDocumentation(StringRef Doc) { + enum State { + Normal, + FencedCodeblock, + } State = Normal; + std::string CodeFence; + + llvm::raw_string_ostream OS(CommentWithMarkers); + + // The documentation string is processed line by line. + // The raw documentation string does not contain the comment markers + // (e.g. /// or /** */). + // But the comment lexer expects doxygen markers, so add them back. + // We need to use the /// style doxygen markers because the comment could + // contain the closing tag "*/" of a C Style "/** */" comment + // which would break the parsing if we would just enclose the comment text + // with "/** */". + + // Escape doxygen commands inside markdown inline code spans. + // This is required to not let the doxygen parser interpret them as + // commands. + // Note: This is a heuristic which may fail in some cases. + bool InCodeSpan = false; + + llvm::StringRef Line, Rest; + for (std::tie(Line, Rest) = Doc.split('\n'); !(Line.empty() && Rest.empty()); + std::tie(Line, Rest) = Rest.split('\n')) { + + // Detect code fence (``` or ~~~) + if (State == Normal) { + llvm::StringRef Trimmed = Line.ltrim(); + if (Trimmed.starts_with("```") || Trimmed.starts_with("~~~")) { + // https://www.doxygen.nl/manual/markdown.html#md_fenced + CodeFence = + Trimmed.take_while([](char C) { return C == '`' || C == '~'; }) + .str(); + // Try to detect language: first word after fence. Could also be + // enclosed in {} + llvm::StringRef AfterFence = + Trimmed.drop_front(CodeFence.size()).ltrim(); + // ignore '{' at the beginning of the language name to not duplicate it + // for the doxygen command + AfterFence.consume_front("{"); + // The name is alphanumeric or '.' or '+' + StringRef CodeLang = AfterFence.take_while( + [](char C) { return llvm::isAlnum(C) || C == '.' || C == '+'; }); + + OS << "///@code"; + + if (!CodeLang.empty()) + OS << "{" << CodeLang.str() << "}"; + + OS << "\n"; + + State = FencedCodeblock; + continue; + } + + // FIXME: handle indented code blocks too? + // In doxygen, the indentation which triggers a code block depends on the + // indentation of the previous paragraph. + // https://www.doxygen.nl/manual/markdown.html#mddox_code_blocks + } else if (State == FencedCodeblock) { + // End of code fence + if (Line.ltrim().starts_with(CodeFence)) { + OS << "///@endcode\n"; + State = Normal; + continue; + } + OS << "///" << Line << "\n"; + continue; + } + + // Normal line preprocessing (add doxygen markers, handle escaping) + OS << "///"; + + if (Line.empty() || Line.trim().empty()) { + OS << "\n"; + // Empty lines reset the InCodeSpan state. + InCodeSpan = false; + continue; + } + + if (Line.starts_with("<")) + // A comment line starting with '///<' is treated as a doxygen + // command. To avoid this, we add a space before the '<'. + OS << ' '; + + for (char C : Line) { + if (C == '`') + InCodeSpan = !InCodeSpan; + else if (InCodeSpan && (C == '@' || C == '\\')) + OS << '\\'; + OS << C; + } + + OS << "\n"; + } + + // Close any unclosed code block + if (State == FencedCodeblock) + OS << "///@endcode\n"; +} + void SymbolDocCommentVisitor::visitBlockCommandComment( const comments::BlockCommandComment *B) { switch (B->getCommandID()) { @@ -282,36 +470,22 @@ void SymbolDocCommentVisitor::visitBlockCommandComment( } break; case comments::CommandTraits::KCI_retval: - RetvalParagraphs.push_back(B->getParagraph()); - return; - case comments::CommandTraits::KCI_warning: - WarningParagraphs.push_back(B->getParagraph()); - return; - case comments::CommandTraits::KCI_note: - NoteParagraphs.push_back(B->getParagraph()); + // Only consider retval commands having an argument. + // The argument contains the described return value which is needed to + // convert it to markup. + if (B->getNumArgs() == 1) + RetvalCommands.push_back(B); return; default: break; } - // For all other commands, we store them in the UnhandledCommands map. + // For all other commands, we store them in the BlockCommands map. // This allows us to keep the order of the comments. - UnhandledCommands[CommentPartIndex] = B; + BlockCommands[CommentPartIndex] = B; CommentPartIndex++; } -void SymbolDocCommentVisitor::paragraphsToMarkup( - markup::Document &Out, - const llvm::SmallVectorImpl &Paragraphs) - const { - if (Paragraphs.empty()) - return; - - for (const auto *P : Paragraphs) { - ParagraphToMarkupDocument(Out.addParagraph(), Traits).visit(P); - } -} - void SymbolDocCommentVisitor::briefToMarkup(markup::Paragraph &Out) const { if (!BriefParagraph) return; @@ -324,14 +498,6 @@ void SymbolDocCommentVisitor::returnToMarkup(markup::Paragraph &Out) const { ParagraphToMarkupDocument(Out, Traits).visit(ReturnParagraph); } -void SymbolDocCommentVisitor::notesToMarkup(markup::Document &Out) const { - paragraphsToMarkup(Out, NoteParagraphs); -} - -void SymbolDocCommentVisitor::warningsToMarkup(markup::Document &Out) const { - paragraphsToMarkup(Out, WarningParagraphs); -} - void SymbolDocCommentVisitor::parameterDocToMarkup( StringRef ParamName, markup::Paragraph &Out) const { if (ParamName.empty()) @@ -352,9 +518,9 @@ void SymbolDocCommentVisitor::parameterDocToString( } } -void SymbolDocCommentVisitor::docToMarkup(markup::Document &Out) const { +void SymbolDocCommentVisitor::detailedDocToMarkup(markup::Document &Out) const { for (unsigned I = 0; I < CommentPartIndex; ++I) { - if (const auto *BC = UnhandledCommands.lookup(I)) { + if (const auto *BC = BlockCommands.lookup(I)) { BlockCommentToMarkupDocument(Out, Traits).visit(BC); } else if (const auto *P = FreeParagraphs.lookup(I)) { ParagraphToMarkupDocument(Out.addParagraph(), Traits).visit(P); @@ -382,5 +548,14 @@ void SymbolDocCommentVisitor::templateTypeParmDocToString( } } +void SymbolDocCommentVisitor::retvalsToMarkup(markup::Document &Out) const { + if (RetvalCommands.empty()) + return; + markup::BulletList &BL = Out.addBulletList(); + for (const auto *P : RetvalCommands) { + BlockCommentToMarkupDocument(BL.addItem(), Traits).visit(P); + } +} + } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/SymbolDocumentation.h b/clang-tools-extra/clangd/SymbolDocumentation.h index b0d3428dfce20..88c7ade633516 100644 --- a/clang-tools-extra/clangd/SymbolDocumentation.h +++ b/clang-tools-extra/clangd/SymbolDocumentation.h @@ -21,6 +21,7 @@ #include "clang/AST/CommentSema.h" #include "clang/AST/CommentVisitor.h" #include "clang/Basic/SourceManager.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" #include @@ -51,31 +52,8 @@ class SymbolDocCommentVisitor CommentWithMarkers.reserve(Documentation.size() + Documentation.count('\n') * 3); - // The comment lexer expects doxygen markers, so add them back. - // We need to use the /// style doxygen markers because the comment could - // contain the closing the closing tag "*/" of a C Style "/** */" comment - // which would break the parsing if we would just enclose the comment text - // with "/** */". - CommentWithMarkers = "///"; - bool NewLine = true; - for (char C : Documentation) { - if (C == '\n') { - CommentWithMarkers += "\n///"; - NewLine = true; - } else { - if (NewLine && (C == '<')) { - // A comment line starting with '///<' is treated as a doxygen - // comment. Therefore add a space to separate the '<' from the comment - // marker. This allows to parse html tags at the beginning of a line - // and the escape marker prevents adding the artificial space in the - // markup documentation. The extra space will not be rendered, since - // we render it as markdown. - CommentWithMarkers += ' '; - } - CommentWithMarkers += C; - NewLine = false; - } - } + preprocessDocumentation(Documentation); + SourceManagerForFile SourceMgrForFile("mock_file.cpp", CommentWithMarkers); SourceManager &SourceMgr = SourceMgrForFile.get(); @@ -100,6 +78,14 @@ class SymbolDocCommentVisitor for (auto *Block : FC->getBlocks()) { visit(Block); } + + // If we have not seen a brief command, use the very first free paragraph as + // the brief. + if (!BriefParagraph && !FreeParagraphs.empty() && + FreeParagraphs.contains(0)) { + BriefParagraph = FreeParagraphs.lookup(0); + FreeParagraphs.erase(0); + } } bool isParameterDocumented(StringRef ParamName) const { @@ -114,22 +100,18 @@ class SymbolDocCommentVisitor bool hasReturnCommand() const { return ReturnParagraph; } - bool hasRetvalCommands() const { return !RetvalParagraphs.empty(); } - - bool hasNoteCommands() const { return !NoteParagraphs.empty(); } - - bool hasWarningCommands() const { return !WarningParagraphs.empty(); } + bool hasDetailedDoc() const { + return !FreeParagraphs.empty() || !BlockCommands.empty(); + } /// Converts all unhandled comment commands to a markup document. - void docToMarkup(markup::Document &Out) const; + void detailedDocToMarkup(markup::Document &Out) const; /// Converts the "brief" command(s) to a markup document. void briefToMarkup(markup::Paragraph &Out) const; /// Converts the "return" command(s) to a markup document. void returnToMarkup(markup::Paragraph &Out) const; - /// Converts the "note" command(s) to a markup document. - void notesToMarkup(markup::Document &Out) const; - /// Converts the "warning" command(s) to a markup document. - void warningsToMarkup(markup::Document &Out) const; + /// Converts the "retval" command(s) to a markup document. + void retvalsToMarkup(markup::Document &Out) const; void visitBlockCommandComment(const comments::BlockCommandComment *B); @@ -145,8 +127,10 @@ class SymbolDocCommentVisitor llvm::raw_string_ostream &Out) const; void visitParagraphComment(const comments::ParagraphComment *P) { - FreeParagraphs[CommentPartIndex] = P; - CommentPartIndex++; + if (!P->isWhitespace()) { + FreeParagraphs[CommentPartIndex] = P; + CommentPartIndex++; + } } void visitParamCommandComment(const comments::ParamCommandComment *P) { @@ -157,6 +141,27 @@ class SymbolDocCommentVisitor TemplateParameters[TP->getParamNameAsWritten()] = std::move(TP); } + /// \brief Preprocesses the raw documentation string to prepare it for doxygen + /// parsing. + /// + /// This is a workaround to provide better support for markdown in + /// doxygen. Clang's doxygen parser e.g. does not handle markdown code blocks. + /// + /// The documentation string is preprocessed to replace some markdown + /// constructs with parsable doxygen commands. E.g. markdown code blocks are + /// replaced with doxygen \\code{.lang} ... + /// \\endcode blocks. + /// + /// Additionally, potential doxygen commands inside markdown + /// inline code spans are escaped to avoid that doxygen tries to interpret + /// them as commands. + /// + /// \note Although this is a workaround, it is very similar to what + /// doxygen itself does for markdown. In doxygen, the first parsing step is + /// also a markdown preprocessing step. + /// See https://www.doxygen.nl/manual/markdown.html + void preprocessDocumentation(StringRef Doc); + private: comments::CommandTraits Traits; llvm::BumpPtrAllocator Allocator; @@ -173,19 +178,13 @@ class SymbolDocCommentVisitor /// Paragraph of the "return" command. const comments::ParagraphComment *ReturnParagraph = nullptr; - /// Paragraph(s) of the "note" command(s) - llvm::SmallVector RetvalParagraphs; + /// All the "retval" command(s) + llvm::SmallVector RetvalCommands; - /// Paragraph(s) of the "note" command(s) - llvm::SmallVector NoteParagraphs; - - /// Paragraph(s) of the "warning" command(s) - llvm::SmallVector WarningParagraphs; - - /// All the paragraphs we don't have any special handling for, - /// e.g. "details". + /// All the parsed doxygen block commands. + /// They might have special handling internally like \\note or \\warning llvm::SmallDenseMap - UnhandledCommands; + BlockCommands; /// Parsed paragaph(s) of the "param" comamnd(s) llvm::SmallDenseMap @@ -198,11 +197,6 @@ class SymbolDocCommentVisitor /// All "free" text paragraphs. llvm::SmallDenseMap FreeParagraphs; - - void paragraphsToMarkup( - markup::Document &Out, - const llvm::SmallVectorImpl - &Paragraphs) const; }; } // namespace clangd diff --git a/clang-tools-extra/clangd/support/Markup.cpp b/clang-tools-extra/clangd/support/Markup.cpp index 89bdc656d440f..304917de252bf 100644 --- a/clang-tools-extra/clangd/support/Markup.cpp +++ b/clang-tools-extra/clangd/support/Markup.cpp @@ -199,10 +199,16 @@ bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After, return needsLeadingEscapeMarkdown(C, After); } -/// Escape a markdown text block. +/// \brief Render text for markdown output. +/// /// If \p EscapeMarkdown is true it ensures the punctuation will not introduce /// any of the markdown constructs. +/// /// Else, markdown syntax is not escaped, only HTML tags and entities. +/// HTML is escaped because usually clients do not support HTML rendering by +/// default. Passing unescaped HTML will therefore often result in not showing +/// the HTML at all. +/// \note In markdown code spans, we do not escape anything. std::string renderText(llvm::StringRef Input, bool StartsLine, bool EscapeMarkdown) { std::string R; @@ -213,6 +219,10 @@ std::string renderText(llvm::StringRef Input, bool StartsLine, bool IsFirstLine = true; + // Inside markdown code spans, we do not escape anything when EscapeMarkdown + // is false. + bool InCodeSpan = false; + for (std::tie(Line, Rest) = Input.split('\n'); !(Line.empty() && Rest.empty()); std::tie(Line, Rest) = Rest.split('\n')) { @@ -226,12 +236,27 @@ std::string renderText(llvm::StringRef Input, bool StartsLine, R.append(LeadingSpaces); } + // Handle the case where the user escaped a character themselves. + // This is relevant for markdown code spans if EscapeMarkdown is false, + // because if the user escaped a backtick, we must treat the enclosed text + // as normal markdown text. + bool UserEscape = false; for (unsigned I = LeadingSpaces.size(); I < Line.size(); ++I) { - if (needsLeadingEscape(Line[I], Line.substr(LeadingSpaces.size(), I), + + if (!EscapeMarkdown && !UserEscape && Line[I] == '`') + InCodeSpan = !InCodeSpan; + + if (!InCodeSpan && + needsLeadingEscape(Line[I], Line.substr(LeadingSpaces.size(), I), Line.substr(I + 1), StartsLineIntern, EscapeMarkdown)) R.push_back('\\'); R.push_back(Line[I]); + + if (Line[I] == '\\') + UserEscape = !UserEscape; + else + UserEscape = false; } IsFirstLine = false; diff --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp index 2c7f50d8c9e4c..95bf5e54fc792 100644 --- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp @@ -235,7 +235,8 @@ TEST_F(LSPTest, ClangTidyRename) { .takeValue() .getAsArray())[0]; - ASSERT_EQ((*RenameCommand.getAsObject())["title"], "change 'foo' to 'Foo'"); + ASSERT_EQ((*RenameCommand.getAsObject())["title"], + "Apply fix: change 'foo' to 'Foo'"); Client.expectServerCall("workspace/applyEdit"); Client.call("workspace/executeCommand", RenameCommand); diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index e9abf71e6d1b6..718c1bc5f355a 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -3457,13 +3457,15 @@ template class Foo {} ``` --- -**Template Parameters:** +### Brief -- `typename T` -- `typename C = bool` +documentation --- -documentation +### Template Parameters + +- `typename T` +- `typename C = bool` --- Size: 10 bytes)", @@ -3506,7 +3508,7 @@ ret_type foo(params) {} ``` --- -**Parameters:** +### Parameters - - `type (aka can_type)` @@ -3514,7 +3516,7 @@ ret_type foo(params) {} - `type foo = default (aka can_type)` --- -**Returns:** +### Returns `ret_type (aka can_ret_type)`)", }, @@ -3649,7 +3651,7 @@ protected: size_t method() ``` --- -**Returns:** +### Returns `size_t (aka unsigned long)`)", }, @@ -3688,7 +3690,7 @@ public: cls(int a, int b = 5) ``` --- -**Parameters:** +### Parameters - `int a` - `int b = 5`)", @@ -4001,9 +4003,13 @@ void foo() ``` --- +### Brief + brief doc --- +### Details + longer doc)"}, {[](HoverInfo &HI) { HI.Kind = index::SymbolKind::Function; @@ -4034,20 +4040,34 @@ int foo() ``` --- +### Brief + brief doc --- -**Returns:** +### Returns `int` --- +### Details + longer doc)"}, {[](HoverInfo &HI) { HI.Kind = index::SymbolKind::Function; - HI.Documentation = "@brief brief doc\n\n" - "longer doc\n@param a this is a param\n@return it " - "returns something"; + HI.Documentation = R"(@brief brief doc + +longer doc +@note this is a note + +As you see, notes are "inlined". +@warning this is a warning + +As well as warnings +@param a this is a param +@return it returns something +@retval 0 if successful +@retval 1 if failed)"; HI.Definition = "int foo(int a)"; HI.ReturnType = "int"; HI.Name = "foo"; @@ -4068,8 +4088,16 @@ longer doc)"}, @brief brief doc longer doc +@note this is a note + +As you see, notes are "inlined". +@warning this is a warning + +As well as warnings @param a this is a param @return it returns something +@retval 0 if successful +@retval 1 if failed --- ```cpp @@ -4083,20 +4111,37 @@ int foo(int a) ``` --- +### Brief + brief doc --- -**Parameters:** +### Parameters - `int a` - this is a param --- -**Returns:** +### Returns `int` - it returns something +- `0` - if successful +- `1` - if failed + --- -longer doc)"}, +### Details + +longer doc + +**Note:** +this is a note + +As you see, notes are "inlined". + +**Warning:** +this is a warning + +As well as warnings)"}, {[](HoverInfo &HI) { HI.Kind = index::SymbolKind::Function; HI.Documentation = "@brief brief doc\n\n" @@ -4138,19 +4183,23 @@ int foo(int a) ``` --- +### Brief + brief doc --- -**Parameters:** +### Parameters - `int a` - this is a param --- -**Returns:** +### Returns `int` - it returns something --- +### Details + longer doc)"}, }; diff --git a/clang-tools-extra/clangd/unittests/SymbolDocumentationTests.cpp b/clang-tools-extra/clangd/unittests/SymbolDocumentationTests.cpp index 31a6a149e33c4..b3185cc10dd5a 100644 --- a/clang-tools-extra/clangd/unittests/SymbolDocumentationTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolDocumentationTests.cpp @@ -15,7 +15,7 @@ namespace clang { namespace clangd { -TEST(SymbolDocumentation, UnhandledDocs) { +TEST(SymbolDocumentation, DetailedDocToMarkup) { CommentOptions CommentOpts; @@ -26,52 +26,52 @@ TEST(SymbolDocumentation, UnhandledDocs) { llvm::StringRef ExpectedRenderPlainText; } Cases[] = { { - "foo bar", + "brief\n\nfoo bar", "foo bar", "foo bar", "foo bar", }, { - "foo\nbar\n", + "brief\n\nfoo\nbar\n", "foo\nbar", "foo\nbar", "foo bar", }, { - "foo\n\nbar\n", + "brief\n\nfoo\n\nbar\n", "foo\n\nbar", "foo\n\nbar", "foo\n\nbar", }, { - "foo \\p bar baz", + "brief\n\nfoo \\p bar baz", "foo `bar` baz", "foo `bar` baz", "foo bar baz", }, { - "foo \\e bar baz", + "brief\n\nfoo \\e bar baz", "foo \\*bar\\* baz", "foo *bar* baz", "foo *bar* baz", }, { - "foo \\b bar baz", + "brief\n\nfoo \\b bar baz", "foo \\*\\*bar\\*\\* baz", "foo **bar** baz", "foo **bar** baz", }, { - "foo \\ref bar baz", - "foo \\*\\*\\\\ref\\*\\* \\*bar\\* baz", - "foo **\\ref** *bar* baz", - "foo **\\ref** *bar* baz", + "brief\n\nfoo \\ref bar baz", + "foo \\*\\*\\\\ref\\*\\* `bar` baz", + "foo **\\ref** `bar` baz", + "foo **\\ref** bar baz", }, { - "foo @ref bar baz", - "foo \\*\\*@ref\\*\\* \\*bar\\* baz", - "foo **@ref** *bar* baz", - "foo **@ref** *bar* baz", + "brief\n\nfoo @ref bar baz", + "foo \\*\\*@ref\\*\\* `bar` baz", + "foo **@ref** `bar` baz", + "foo **@ref** bar baz", }, { "\\brief this is a \\n\nbrief description", @@ -80,10 +80,10 @@ TEST(SymbolDocumentation, UnhandledDocs) { "", }, { - "\\throw exception foo", - "\\*\\*\\\\throw\\*\\* \\*exception\\* foo", - "**\\throw** *exception* foo", - "**\\throw** *exception* foo", + "brief\n\n\\throw exception foo", + "\\*\\*\\\\throw\\*\\* `exception` foo", + "**\\throw** `exception` foo", + "**\\throw** exception foo", }, { R"(\brief this is a brief description @@ -108,7 +108,8 @@ TEST(SymbolDocumentation, UnhandledDocs) { - item 3)", }, { - "\\defgroup mygroup this is a group\nthis is not a group description", + "brief\n\n\\defgroup mygroup this is a group\nthis is not a group " + "description", "\\*\\*@defgroup\\*\\* `mygroup this is a group`\n\nthis is not a " "group " "description", @@ -118,7 +119,9 @@ TEST(SymbolDocumentation, UnhandledDocs) { "description", }, { - R"(\verbatim + R"(brief + +\verbatim this is a verbatim block containing some verbatim text @@ -150,7 +153,7 @@ some verbatim text **@endverbatim**)", }, { - "@param foo this is a parameter\n@param bar this is another " + "brief\n\n@param foo this is a parameter\n@param bar this is another " "parameter", "", "", @@ -169,24 +172,26 @@ More description documentation)", R"(\*\*\\brief\*\* another brief? -\*\*\\details\*\* these are details +these are details More description documentation)", R"(**\brief** another brief? -**\details** these are details +these are details More description documentation)", R"(**\brief** another brief? -**\details** these are details +these are details More description documentation)", }, { - R"(this is a bold text + R"(brief + +this is a bold text normal textthis is an italic text this is a code block)", R"(\this is a bold text\ @@ -198,12 +203,528 @@ normal text\this is an italic text\ "this is a bold text normal textthis is an italic text " "this is a code block", }, + {"brief\n\n@note This is a note", + R"(\*\*Note:\*\* +This is a note)", + R"(**Note:** +This is a note)", + R"(**Note:** +This is a note)"}, + {R"(brief + +Paragraph 1 +@note This is a note + +Paragraph 2)", + R"(Paragraph 1 + +\*\*Note:\*\* +This is a note + +Paragraph 2)", + R"(Paragraph 1 + +**Note:** +This is a note + +Paragraph 2)", + R"(Paragraph 1 + +**Note:** +This is a note + +Paragraph 2)"}, + {"brief\n\n@warning This is a warning", + R"(\*\*Warning:\*\* +This is a warning)", + R"(**Warning:** +This is a warning)", + R"(**Warning:** +This is a warning)"}, + {R"(brief + +Paragraph 1 +@warning This is a warning + +Paragraph 2)", + R"(Paragraph 1 + +\*\*Warning:\*\* +This is a warning + +Paragraph 2)", + R"(Paragraph 1 + +**Warning:** +This is a warning + +Paragraph 2)", + R"(Paragraph 1 + +**Warning:** +This is a warning + +Paragraph 2)"}, + {R"(@note this is not treated as brief + +@brief this is the brief + +Another paragraph)", + R"(\*\*Note:\*\* +this is not treated as brief + +Another paragraph)", + R"(**Note:** +this is not treated as brief + +Another paragraph)", + R"(**Note:** +this is not treated as brief + +Another paragraph)"}, + {R"( +@brief Some brief +)", + "", "", ""}, + {R"( +Some brief +)", + "", "", ""}, + }; + for (const auto &C : Cases) { + markup::Document Doc; + SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); + + SymbolDoc.detailedDocToMarkup(Doc); + + EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); + EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); + EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown); + } +} + +TEST(SymbolDocumentation, RetvalCommand) { + + CommentOptions CommentOpts; + + struct Case { + llvm::StringRef Documentation; + llvm::StringRef ExpectedRenderEscapedMarkdown; + llvm::StringRef ExpectedRenderMarkdown; + llvm::StringRef ExpectedRenderPlainText; + } Cases[] = { + {"@retval", "", "", ""}, + {R"(@retval MyReturnVal +@retval MyOtherReturnVal)", + R"(- `MyReturnVal` +- `MyOtherReturnVal`)", + R"(- `MyReturnVal` +- `MyOtherReturnVal`)", + R"(- MyReturnVal +- MyOtherReturnVal)"}, + {R"(@retval MyReturnVal if foo +@retval MyOtherReturnVal if bar)", + R"(- `MyReturnVal` - if foo +- `MyOtherReturnVal` - if bar)", + R"(- `MyReturnVal` - if foo +- `MyOtherReturnVal` - if bar)", + R"(- MyReturnVal - if foo +- MyOtherReturnVal - if bar)"}, + }; + for (const auto &C : Cases) { + markup::Document Doc; + SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); + + SymbolDoc.retvalsToMarkup(Doc); + + EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); + EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); + EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown); + } +} + +TEST(SymbolDocumentation, DoxygenCodeBlocks) { + CommentOptions CommentOpts; + + struct Case { + llvm::StringRef Documentation; + llvm::StringRef ExpectedRenderEscapedMarkdown; + llvm::StringRef ExpectedRenderMarkdown; + llvm::StringRef ExpectedRenderPlainText; + } Cases[] = { + {R"(@code +int code() { return 0; } +@endcode +@code{.cpp} +int code_lang() { return 0; } +@endcode +@code{.c++} +int code_lang_plus() { return 0; } +@endcode +@code{.py} +class A: + pass +@endcode +@code{nolang} +class B: + pass +@endcode)", + R"(``` +int code() { return 0; } +``` + +```cpp +int code_lang() { return 0; } +``` + +```c++ +int code_lang_plus() { return 0; } +``` + +```py +class A: + pass +``` + +```nolang +class B: + pass +```)", + R"(``` +int code() { return 0; } +``` + +```cpp +int code_lang() { return 0; } +``` + +```c++ +int code_lang_plus() { return 0; } +``` + +```py +class A: + pass +``` + +```nolang +class B: + pass +```)", + R"(int code() { return 0; } + +int code_lang() { return 0; } + +int code_lang_plus() { return 0; } + +class A: + pass + +class B: + pass)"}, + }; + for (const auto &C : Cases) { + markup::Document Doc; + SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); + + SymbolDoc.detailedDocToMarkup(Doc); + + EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); + EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); + EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown); + } +} + +TEST(SymbolDocumentation, MarkdownCodeBlocks) { + CommentOptions CommentOpts; + + struct Case { + llvm::StringRef Documentation; + llvm::StringRef ExpectedRenderEscapedMarkdown; + llvm::StringRef ExpectedRenderMarkdown; + llvm::StringRef ExpectedRenderPlainText; + } Cases[] = { + {R"(``` +int backticks() { return 0; } +``` +```cpp +int backticks_lang() { return 0; } +``` +```c++ +int backticks_lang_plus() { return 0; } +``` +~~~ +int tilde() { return 0; } +~~~ +~~~~~~~~~~~~~~~~~~~~~~~~ +int tilde_many() { return 0; } +~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~{.c++} +int tilde_many_lang() { return 0; } +~~~~~~~~~~~~~~~~~~~~~~~~ +```py +class A: + pass +``` +```python +class B: + pass +``` +~~~{.python} +class C: + pass +~~~ +)", + R"(``` +int backticks() { return 0; } +``` + +```cpp +int backticks_lang() { return 0; } +``` + +```c++ +int backticks_lang_plus() { return 0; } +``` + +``` +int tilde() { return 0; } +``` + +``` +int tilde_many() { return 0; } +``` + +```c++ +int tilde_many_lang() { return 0; } +``` + +```py +class A: + pass +``` + +```python +class B: + pass +``` + +```python +class C: + pass +```)", + R"(``` +int backticks() { return 0; } +``` + +```cpp +int backticks_lang() { return 0; } +``` + +```c++ +int backticks_lang_plus() { return 0; } +``` + +``` +int tilde() { return 0; } +``` + +``` +int tilde_many() { return 0; } +``` + +```c++ +int tilde_many_lang() { return 0; } +``` + +```py +class A: + pass +``` + +```python +class B: + pass +``` + +```python +class C: + pass +```)", + R"(int backticks() { return 0; } + +int backticks_lang() { return 0; } + +int backticks_lang_plus() { return 0; } + +int tilde() { return 0; } + +int tilde_many() { return 0; } + +int tilde_many_lang() { return 0; } + +class A: + pass + +class B: + pass + +class C: + pass)"}, + {R"(``` +// this code block is missing end backticks + +)", + R"(``` +// this code block is missing end backticks +```)", + R"(``` +// this code block is missing end backticks +```)", + R"(// this code block is missing end backticks)"}, + }; + for (const auto &C : Cases) { + markup::Document Doc; + SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); + + SymbolDoc.detailedDocToMarkup(Doc); + + EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); + EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); + EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown); + } +} + +TEST(SymbolDocumentation, MarkdownCodeBlocksSeparation) { + CommentOptions CommentOpts; + + struct Case { + llvm::StringRef Documentation; + llvm::StringRef ExpectedRenderEscapedMarkdown; + llvm::StringRef ExpectedRenderMarkdown; + llvm::StringRef ExpectedRenderPlainText; + } Cases[] = { + {R"(@note Show that code blocks are correctly separated +``` +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +```)", + R"(\*\*Note:\*\* +Show that code blocks are correctly separated + +``` +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +```)", + R"(**Note:** +Show that code blocks are correctly separated + +``` +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +```)", + R"(**Note:** +Show that code blocks are correctly separated + +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; })"}, + {R"(@note Show that code blocks are correctly separated +~~~~~~~~~ +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +~~~~~~~~~)", + R"(\*\*Note:\*\* +Show that code blocks are correctly separated + +``` +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +```)", + R"(**Note:** +Show that code blocks are correctly separated + +``` +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; } +```)", + R"(**Note:** +Show that code blocks are correctly separated + +/// Without the markdown preprocessing, this line and the line above would be part of the @note paragraph. + +/// With preprocessing, the code block is correctly separated from the @note paragraph. +/// Also note that without preprocessing, all doxygen commands inside code blocks, like @p would be incorrectly interpreted. +int function() { return 0; })"}, + }; + for (const auto &C : Cases) { + markup::Document Doc; + SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); + + SymbolDoc.detailedDocToMarkup(Doc); + + EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); + EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); + EXPECT_EQ(Doc.asEscapedMarkdown(), C.ExpectedRenderEscapedMarkdown); + } +} + +TEST(SymbolDocumentation, MarkdownCodeSpans) { + CommentOptions CommentOpts; + + struct Case { + llvm::StringRef Documentation; + llvm::StringRef ExpectedRenderEscapedMarkdown; + llvm::StringRef ExpectedRenderMarkdown; + llvm::StringRef ExpectedRenderPlainText; + } Cases[] = { + {R"(`this is a code span with @p and \c inside`)", + R"(\`this is a code span with @p and \\c inside\`)", + R"(`this is a code span with @p and \c inside`)", + R"(`this is a code span with @p and \c inside`)"}, + {R"( ``)", R"(\ \`\\`)", + R"(\ ``)", R"( ``)"}, + {R"( \` doxygen commands not parsed @p, \c, @note, \warning \`)", + R"(\ \\\`\ doxygen commands not parsed @p, \\c, @note, \\warning \\\`)", + R"(\ \`\ doxygen commands not parsed @p, \c, @note, \warning \`)", + R"( \` doxygen commands not parsed @p, \c, @note, \warning \`)"}, + {R"(`multi +line +\c span`)", + R"(\`multi +line +\\c span\`)", + R"(`multi +line +\c span`)", + R"(`multi line +\c span`)"}, }; for (const auto &C : Cases) { markup::Document Doc; SymbolDocCommentVisitor SymbolDoc(C.Documentation, CommentOpts); - SymbolDoc.docToMarkup(Doc); + SymbolDoc.briefToMarkup(Doc.addParagraph()); EXPECT_EQ(Doc.asPlainText(), C.ExpectedRenderPlainText); EXPECT_EQ(Doc.asMarkdown(), C.ExpectedRenderMarkdown); diff --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp index b5f09f9b14604..02133ec5d77a3 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp @@ -15,6 +15,8 @@ namespace clang { namespace clangd { namespace { +using ::testing::UnorderedElementsAre; + TWEAK_TEST(DefineOutline); TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) { @@ -747,6 +749,43 @@ TEST_F(DefineOutlineTest, FailsMacroSpecifier) { } } +TWEAK_WORKSPACE_TEST(DefineOutline); + +// Test that DefineOutline's use of getCorrespondingHeaderOrSource() +// to find the source file corresponding to a header file in which the +// tweak is invoked is working as intended. +TEST_F(DefineOutlineWorkspaceTest, FindsCorrespondingSource) { + llvm::Annotations HeaderBefore(R"cpp( +class A { + void bar(); + void f^oo(){} +}; +)cpp"); + std::string SourceBefore(R"cpp( +#include "a.hpp" +void A::bar(){} +)cpp"); + std::string HeaderAfter = R"cpp( +class A { + void bar(); + void foo(); +}; +)cpp"; + std::string SourceAfter = R"cpp( +#include "a.hpp" +void A::bar(){} +void A::foo(){} +)cpp"; + Workspace.addSource("a.hpp", HeaderBefore.code()); + Workspace.addMainFile("a.cpp", SourceBefore); + auto Result = apply("a.hpp", {HeaderBefore.point(), HeaderBefore.point()}); + EXPECT_THAT(Result, + AllOf(withStatus("success"), + editedFiles(UnorderedElementsAre( + FileWithContents(testPath("a.hpp"), HeaderAfter), + FileWithContents(testPath("a.cpp"), SourceAfter))))); +} + } // namespace } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp index 81e65ede00781..c26fc21d7a01c 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.cpp @@ -162,5 +162,37 @@ std::string TweakTest::decorate(llvm::StringRef Code, .str(); } +// TODO: Reuse more code between TweakTest::apply() and +// TweakWorkspaceTest::apply(). +TweakResult +TweakWorkspaceTest::apply(StringRef InvocationFile, + llvm::Annotations::Range InvocationRange) { + auto AST = Workspace.openFile(InvocationFile); + if (!AST) { + ADD_FAILURE() << "No file '" << InvocationFile << "' in workspace"; + return TweakResult{"failed to setup"}; + } + + auto Index = Workspace.index(); + auto Result = applyTweak( + *AST, InvocationRange, TweakID, Index.get(), + &AST->getSourceManager().getFileManager().getVirtualFileSystem()); + if (!Result) + return TweakResult{"unavailable"}; + if (!*Result) + return TweakResult{"fail: " + llvm::toString(Result->takeError())}; + const auto &Effect = **Result; + if ((*Result)->ShowMessage) + return TweakResult{"message:\n" + *Effect.ShowMessage}; + + TweakResult Retval{"success"}; + for (auto &It : Effect.ApplyEdits) { + auto NewText = It.second.apply(); + if (!NewText) + return TweakResult{"bad edits: " + llvm::toString(NewText.takeError())}; + Retval.EditedFiles.insert_or_assign(It.first(), *NewText); + } + return Retval; +} } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h index 9c6b1f9c000ae..867398513880c 100644 --- a/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h +++ b/clang-tools-extra/clangd/unittests/tweaks/TweakTesting.h @@ -10,6 +10,7 @@ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TWEAKS_TWEAKTESTING_H #include "ParsedAST.h" +#include "TestWorkspace.h" #include "index/Index.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" @@ -123,6 +124,73 @@ MATCHER_P2(FileWithContents, FileName, Contents, "") { #define EXPECT_AVAILABLE(MarkedCode) EXPECT_AVAILABLE_(MarkedCode, true) #define EXPECT_UNAVAILABLE(MarkedCode) EXPECT_AVAILABLE_(MarkedCode, false) +// A helper class to represent the return value of TweakWorkspaceTest::apply(). +struct TweakResult { + // A string representation the status of the operation. + // For failure cases, this is the same as the return value of + // TweakTest::apply() (see the comment above that for details). + // For success cases, this is "success". + std::string Status; + // The contents of all files changed by the tweak, including + // the file in which it was invoked. Keys are absolute paths. + llvm::StringMap EditedFiles = {}; +}; + +// GTest matchers to allow more easily writing assertions about the +// expected value of a TweakResult. +MATCHER_P(withStatus, S, "") { return arg.Status == S; } +template +::testing::Matcher editedFiles(EditedFilesMatcher M) { + return ::testing::Field(&TweakResult::EditedFiles, M); +} + +// Used for formatting TweakResult objects in assertion failure messages, +// so it's easier to understand what didn't match. +inline llvm::raw_ostream &operator<<(llvm::raw_ostream &Stream, + const TweakResult &Result) { + Stream << "{ status: " << Result.Status << ", editedFiles: ["; + for (const auto &F : Result.EditedFiles) { + Stream << F.first() << ":\n"; + Stream << F.second; + } + return Stream << "] }"; +} + +// A version of TweakTest that makes it easier to create test cases that +// involve multiple files which are indexed. +// Usage: +// - Call `Workspace.addMainFile(filename, contents)` to add +// source files which are indexer entry points (e.g. would show +// up in `compile_commands.json`). +// - Call `Workspace.addSource(filename, contents)` to add other +// source files (e.g. header files). +// - Call `apply(filename, range)` to invoke the tweak on the +// indicated file with the given range selected. Can be called +// multiple times for the same set of added files. +// The implementation takes care of building an index reflecting +// all added source files, and making it available to the tweak. +// Unlike TweakTest, this does not have a notion of a `CodeContext` +// (i.e. the contents of all added files are interpreted as being +// in a File context). +class TweakWorkspaceTest : public ::testing::Test { + const char *TweakID; + +public: + TweakWorkspaceTest(const char *TweakID) : TweakID(TweakID) {} + + TweakResult apply(StringRef InvocationFile, + llvm::Annotations::Range InvocationRange); + +protected: + TestWorkspace Workspace; +}; + +#define TWEAK_WORKSPACE_TEST(TweakID) \ + class TweakID##WorkspaceTest : public ::clang::clangd::TweakWorkspaceTest { \ + protected: \ + TweakID##WorkspaceTest() : TweakWorkspaceTest(#TweakID) {} \ + } + } // namespace clangd } // namespace clang diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 4197abac273b0..33cc401bcb78f 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -49,6 +49,10 @@ Major New Features Potentially Breaking Changes ---------------------------- +- Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been + moved to the ``fuchsia`` module instead. The ``zircon`` module will be removed + in the 24th release. + - Removed :program:`clang-tidy`'s global options `IgnoreMacros` and `StrictMode`, which were documented as deprecated since :program:`clang-tidy-20`. Users should use the check-specific options of the @@ -163,6 +167,10 @@ Improvements to clang-tidy scripts by adding the `-hide-progress` option to suppress progress and informational messages. +- Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been + moved to the ``fuchsia`` module instead. The ``zircon`` module will be removed + in the 24th release. + New checks ^^^^^^^^^^ @@ -278,6 +286,10 @@ Changes in existing checks ` check by fixing a crash on ``sizeof`` of an array of dependent type. +- Improved :doc:`bugprone-suspicious-include + ` check by adding + `IgnoredRegex` option. + - Improved :doc:`bugprone-tagged-union-member-count ` by fixing a false positive when enums or unions from system header files or the ``std`` @@ -299,6 +311,10 @@ Changes in existing checks an additional matcher that generalizes the copy-and-swap idiom pattern detection. +- Improved :doc:`cppcoreguidelines-init-variables + ` check by fixing the + insertion location for function pointers with multiple parameters. + - Improved :doc:`cppcoreguidelines-prefer-member-initializer ` check to avoid false positives on inherited members in class templates. @@ -320,7 +336,8 @@ Changes in existing checks - Improved :doc:`misc-const-correctness ` check to avoid false - positives when pointers is tranferred to non-const references. + positives when pointers is tranferred to non-const references + and avoid false positives of function pointer. - Improved :doc:`misc-header-include-cycle ` check performance. @@ -385,6 +402,11 @@ Changes in existing checks declarations and macros in system headers. The documentation is also improved to differentiate the general options from the specific ones. +- Improved :doc:`readability-implicit-bool-conversion + ` check by correctly + adding parentheses when the inner expression are implicitly converted + multiple times. + - Improved :doc:`readability-qualified-auto ` check by adding the option `IgnoreAliasing`, that allows not looking at underlying types of type aliases. diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst index 669654fdd435f..4fbfa259f3d09 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst @@ -14,3 +14,11 @@ Examples: #include "Pterodactyl.h" // OK, .h files tend not to have definitions. #include "Velociraptor.cpp" // Warning, filename is suspicious. #include_next // Warning, filename is suspicious. + +Options +------- + +.. option:: IgnoredRegex + + A regular expression for the file name to be ignored by the check. Default + is empty string. diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/temporary-objects.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/temporary-objects.rst new file mode 100644 index 0000000000000..29005c4dbcc0c --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/temporary-objects.rst @@ -0,0 +1,53 @@ +.. title:: clang-tidy - fuchsia-temporary-objects + +fuchsia-temporary-objects +========================= + +Warns on construction of specific temporary objects in the Zircon kernel. +If the object should be flagged, the fully qualified type name must be +explicitly passed to the check. + +For example, given the list of classes "Foo" and "NS::Bar", all of the +following will trigger the warning: + +.. code-block:: c++ + + Foo(); + Foo F = Foo(); + func(Foo()); + + namespace NS { + + Bar(); + + } + +With the same list, the following will not trigger the warning: + +.. code-block:: c++ + + Foo F; // Non-temporary construction okay + Foo F(param); // Non-temporary construction okay + Foo *F = new Foo(); // New construction okay + + Bar(); // Not NS::Bar, so okay + NS::Bar B; // Non-temporary construction okay + +Note that objects must be explicitly specified in order to be flagged, +and so objects that inherit a specified object will not be flagged. + +This check matches temporary objects without regard for inheritance and so a +prohibited base class type does not similarly prohibit derived class types. + +.. code-block:: c++ + + class Derived : Foo {} // Derived is not explicitly disallowed + Derived(); // and so temporary construction is okay + +Options +------- + +.. option:: Names + + A semi-colon-separated list of fully-qualified names of C++ classes that + should not be constructed as temporaries. Default is empty string. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index f94696d4ef9c7..a324d18704c01 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -222,6 +222,7 @@ Clang-Tidy Checks :doc:`fuchsia-multiple-inheritance `, :doc:`fuchsia-overloaded-operator `, :doc:`fuchsia-statically-constructed-objects `, + :doc:`fuchsia-temporary-objects `, :doc:`fuchsia-trailing-return `, :doc:`fuchsia-virtual-inheritance `, :doc:`google-build-explicit-make-pair `, @@ -371,7 +372,7 @@ Clang-Tidy Checks :doc:`readability-avoid-nested-conditional-operator `, :doc:`readability-avoid-return-with-void-value `, "Yes" :doc:`readability-avoid-unconditional-preprocessor-if `, - :doc:`readability-braces-around-statements `, + :doc:`readability-braces-around-statements `, "Yes" :doc:`readability-const-return-type `, "Yes" :doc:`readability-container-contains `, "Yes" :doc:`readability-container-data-pointer `, "Yes" @@ -570,12 +571,12 @@ Check aliases :doc:`cppcoreguidelines-non-private-member-variables-in-classes `, :doc:`misc-non-private-member-variables-in-classes `, :doc:`cppcoreguidelines-use-default-member-init `, :doc:`modernize-use-default-member-init `, "Yes" :doc:`fuchsia-header-anon-namespaces `, :doc:`google-build-namespaces `, - :doc:`google-readability-braces-around-statements `, :doc:`readability-braces-around-statements `, + :doc:`google-readability-braces-around-statements `, :doc:`readability-braces-around-statements `, "Yes" :doc:`google-readability-function-size `, :doc:`readability-function-size `, :doc:`google-readability-namespace-comments `, :doc:`llvm-namespace-comment `, :doc:`hicpp-avoid-c-arrays `, :doc:`modernize-avoid-c-arrays `, :doc:`hicpp-avoid-goto `, :doc:`cppcoreguidelines-avoid-goto `, - :doc:`hicpp-braces-around-statements `, :doc:`readability-braces-around-statements `, + :doc:`hicpp-braces-around-statements `, :doc:`readability-braces-around-statements `, "Yes" :doc:`hicpp-deprecated-headers `, :doc:`modernize-deprecated-headers `, "Yes" :doc:`hicpp-explicit-conversions `, :doc:`google-explicit-constructor `, "Yes" :doc:`hicpp-function-size `, :doc:`readability-function-size `, diff --git a/clang-tools-extra/docs/clang-tidy/checks/zircon/temporary-objects.rst b/clang-tools-extra/docs/clang-tidy/checks/zircon/temporary-objects.rst index ab1225faa2139..a27822e14c1f6 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/zircon/temporary-objects.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/zircon/temporary-objects.rst @@ -3,51 +3,8 @@ zircon-temporary-objects ======================== -Warns on construction of specific temporary objects in the Zircon kernel. -If the object should be flagged, If the object should be flagged, the fully -qualified type name must be explicitly passed to the check. +.. note:: -For example, given the list of classes "Foo" and "NS::Bar", all of the -following will trigger the warning: - -.. code-block:: c++ - - Foo(); - Foo F = Foo(); - func(Foo()); - - namespace NS { - - Bar(); - - } - -With the same list, the following will not trigger the warning: - -.. code-block:: c++ - - Foo F; // Non-temporary construction okay - Foo F(param); // Non-temporary construction okay - Foo *F = new Foo(); // New construction okay - - Bar(); // Not NS::Bar, so okay - NS::Bar B; // Non-temporary construction okay - -Note that objects must be explicitly specified in order to be flagged, -and so objects that inherit a specified object will not be flagged. - -This check matches temporary objects without regard for inheritance and so a -prohibited base class type does not similarly prohibit derived class types. - -.. code-block:: c++ - - class Derived : Foo {} // Derived is not explicitly disallowed - Derived(); // and so temporary construction is okay - -Options -------- - -.. option:: Names - - A semi-colon-separated list of fully-qualified names of C++ classes that - should not be constructed as temporaries. Default is empty. + The `zircon-temporary-objects` check has been deprecated and will be removed + in 24th release of LLVM. Please use + :doc:`fuchsia-temporary-objects <../fuchsia/temporary-objects>` instead. diff --git a/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp new file mode 100644 index 0000000000000..04fcfc1dc0a85 --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/multiple-namespaces.cpp @@ -0,0 +1,20 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/json/foo_tools.json --check-prefix=CHECK-FOO +// RUN: FileCheck %s < %t/json/bar_tools.json --check-prefix=CHECK-BAR + +namespace foo { + namespace tools { + class FooTools {}; + } // namespace tools +} // namespace foo + +namespace bar { + namespace tools { + class BarTools {}; + } // namespace tools +} // namespace bar + +// CHECK-FOO: "Name": "tools" + +// CHECK-BAR: "Name": "tools" diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp index b19afc1885104..cf19e1e34a818 100644 --- a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %t && mkdir -p %t // RUN: clang-doc --output=%t --format=json --executor=standalone %s // RUN: FileCheck %s < %t/json/nested.json --check-prefix=NESTED -// RUN: FileCheck %s < %t/json/inner.json --check-prefix=INNER +// RUN: FileCheck %s < %t/json/nested_inner.json --check-prefix=INNER namespace nested { int Global; diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/moc_foo.cpp b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/moc_foo.cpp new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/cleanup-ctad.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/cleanup-ctad.cpp index c2b5e4df985d8..53400ac04d3b5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/cleanup-ctad.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/cleanup-ctad.cpp @@ -79,27 +79,27 @@ absl::Cleanup MakeCleanup(Callback callback) { void test() { auto a = absl::MakeCleanup([] {}); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup's class template argument deduction pattern in C++17 and higher - // CHECK-FIXES: {{^}} absl::Cleanup a = [] {};{{$}} + // CHECK-FIXES: absl::Cleanup a = [] {}; auto b = absl::MakeCleanup(std::function([] {})); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher - // CHECK-FIXES: {{^}} absl::Cleanup b = std::function([] {});{{$}} + // CHECK-FIXES: absl::Cleanup b = std::function([] {}); const auto c = absl::MakeCleanup([] {}); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher - // CHECK-FIXES: {{^}} const absl::Cleanup c = [] {};{{$}} + // CHECK-FIXES: const absl::Cleanup c = [] {}; const auto d = absl::MakeCleanup(std::function([] {})); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: prefer absl::Cleanup{{.*}}C++17 and higher - // CHECK-FIXES: {{^}} const absl::Cleanup d = std::function([] {});{{$}} + // CHECK-FIXES: const absl::Cleanup d = std::function([] {}); // Preserves extra parens auto e = absl::MakeCleanup(([] {})); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher - // CHECK-FIXES: {{^}} absl::Cleanup e = ([] {});{{$}} + // CHECK-FIXES: absl::Cleanup e = ([] {}); // Preserves comments auto f = /* a */ absl::MakeCleanup(/* b */ [] { /* c */ } /* d */) /* e */; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer absl::Cleanup{{.*}}C++17 and higher - // CHECK-FIXES: {{^}} absl::Cleanup f = /* a */ /* b */ [] { /* c */ } /* d */ /* e */;{{$}} + // CHECK-FIXES: absl::Cleanup f = /* a */ /* b */ [] { /* c */ } /* d */ /* e */; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp index 562b513d784e6..cc41603394427 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-addition %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-addition %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -8,68 +8,68 @@ void f() { i = absl::ToUnixHours(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixHours(t + absl::Hours(5)) + // CHECK-FIXES: i = absl::ToUnixHours(t + absl::Hours(5)); i = absl::ToUnixMinutes(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMinutes(t + absl::Minutes(5)) + // CHECK-FIXES: i = absl::ToUnixMinutes(t + absl::Minutes(5)); i = absl::ToUnixSeconds(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixSeconds(t + absl::Seconds(5)) + // CHECK-FIXES: i = absl::ToUnixSeconds(t + absl::Seconds(5)); i = absl::ToUnixMillis(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMillis(t + absl::Milliseconds(5)) + // CHECK-FIXES: i = absl::ToUnixMillis(t + absl::Milliseconds(5)); i = absl::ToUnixMicros(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMicros(t + absl::Microseconds(5)) + // CHECK-FIXES: i = absl::ToUnixMicros(t + absl::Microseconds(5)); i = absl::ToUnixNanos(t) + 5; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixNanos(t + absl::Nanoseconds(5)) + // CHECK-FIXES: i = absl::ToUnixNanos(t + absl::Nanoseconds(5)); i = 3 + absl::ToUnixHours(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixHours(absl::Hours(3) + t) + // CHECK-FIXES: i = absl::ToUnixHours(absl::Hours(3) + t); i = 3 + absl::ToUnixMinutes(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMinutes(absl::Minutes(3) + t) + // CHECK-FIXES: i = absl::ToUnixMinutes(absl::Minutes(3) + t); i = 3 + absl::ToUnixSeconds(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixSeconds(absl::Seconds(3) + t) + // CHECK-FIXES: i = absl::ToUnixSeconds(absl::Seconds(3) + t); i = 3 + absl::ToUnixMillis(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMillis(absl::Milliseconds(3) + t) + // CHECK-FIXES: i = absl::ToUnixMillis(absl::Milliseconds(3) + t); i = 3 + absl::ToUnixMicros(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMicros(absl::Microseconds(3) + t) + // CHECK-FIXES: i = absl::ToUnixMicros(absl::Microseconds(3) + t); i = 3 + absl::ToUnixNanos(t); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixNanos(absl::Nanoseconds(3) + t) + // CHECK-FIXES: i = absl::ToUnixNanos(absl::Nanoseconds(3) + t); // Undoing inverse conversions i = absl::ToUnixMicros(t) + absl::ToInt64Microseconds(absl::Seconds(1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixMicros(t + absl::Seconds(1)) + // CHECK-FIXES: i = absl::ToUnixMicros(t + absl::Seconds(1)); // Parens i = 3 + (absl::ToUnixHours(t)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixHours(absl::Hours(3) + t) + // CHECK-FIXES: i = absl::ToUnixHours(absl::Hours(3) + t); // Float folding i = absl::ToUnixSeconds(t) + 5.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixSeconds(t + absl::Seconds(5)) + // CHECK-FIXES: i = absl::ToUnixSeconds(t + absl::Seconds(5)); // We can rewrite the argument of the duration conversion #define THIRTY absl::FromUnixSeconds(30) i = absl::ToUnixSeconds(THIRTY) + 1; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixSeconds(THIRTY + absl::Seconds(1)) + // CHECK-FIXES: i = absl::ToUnixSeconds(THIRTY + absl::Seconds(1)); #undef THIRTY // Some other contexts if (absl::ToUnixSeconds(t) + 1.0 > 10) {} // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixSeconds(t + absl::Seconds(1)) + // CHECK-FIXES: if (absl::ToUnixSeconds(t + absl::Seconds(1)) > 10) {} // These should not match i = 5 + 6; @@ -88,7 +88,7 @@ template void foo(absl::Time t) { int i = absl::ToUnixNanos(t) + T{}; // CHECK-MESSAGES: [[@LINE-1]]:11: warning: perform addition in the duration domain [abseil-duration-addition] - // CHECK-FIXES: absl::ToUnixNanos(t + absl::Nanoseconds(T{})) + // CHECK-FIXES: int i = absl::ToUnixNanos(t + absl::Nanoseconds(T{})); } void g() { diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp index 6110dfded6bac..8f49e71de1242 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-comparison %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -11,104 +11,104 @@ void f() { // Check against the RHS b = x > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) > d1; + // CHECK-FIXES: b = absl::Seconds(x) > d1; b = x >= absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) >= d1; + // CHECK-FIXES: b = absl::Seconds(x) >= d1; b = x == absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) == d1; + // CHECK-FIXES: b = absl::Seconds(x) == d1; b = x <= absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) <= d1; + // CHECK-FIXES: b = absl::Seconds(x) <= d1; b = x < absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) < d1; + // CHECK-FIXES: b = absl::Seconds(x) < d1; b = x == absl::ToDoubleSeconds(t1 - t2); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) == t1 - t2; + // CHECK-FIXES: b = absl::Seconds(x) == t1 - t2; b = absl::ToDoubleSeconds(d1) > absl::ToDoubleSeconds(d2); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 > d2; + // CHECK-FIXES: b = d1 > d2; // Check against the LHS b = absl::ToDoubleSeconds(d1) < x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 < absl::Seconds(x); + // CHECK-FIXES: b = d1 < absl::Seconds(x); b = absl::ToDoubleSeconds(d1) <= x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 <= absl::Seconds(x); + // CHECK-FIXES: b = d1 <= absl::Seconds(x); b = absl::ToDoubleSeconds(d1) == x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 == absl::Seconds(x); + // CHECK-FIXES: b = d1 == absl::Seconds(x); b = absl::ToDoubleSeconds(d1) >= x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 >= absl::Seconds(x); + // CHECK-FIXES: b = d1 >= absl::Seconds(x); b = absl::ToDoubleSeconds(d1) > x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 > absl::Seconds(x); + // CHECK-FIXES: b = d1 > absl::Seconds(x); // Comparison against zero b = absl::ToDoubleSeconds(d1) < 0.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 < absl::ZeroDuration(); + // CHECK-FIXES: b = d1 < absl::ZeroDuration(); b = absl::ToDoubleSeconds(d1) < 0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: d1 < absl::ZeroDuration(); + // CHECK-FIXES: b = d1 < absl::ZeroDuration(); // Scales other than Seconds b = x > absl::ToDoubleMicroseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Microseconds(x) > d1; + // CHECK-FIXES: b = absl::Microseconds(x) > d1; b = x >= absl::ToDoubleMilliseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Milliseconds(x) >= d1; + // CHECK-FIXES: b = absl::Milliseconds(x) >= d1; b = x == absl::ToDoubleNanoseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Nanoseconds(x) == d1; + // CHECK-FIXES: b = absl::Nanoseconds(x) == d1; b = x <= absl::ToDoubleMinutes(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Minutes(x) <= d1; + // CHECK-FIXES: b = absl::Minutes(x) <= d1; b = x < absl::ToDoubleHours(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Hours(x) < d1; + // CHECK-FIXES: b = absl::Hours(x) < d1; // Integer comparisons b = x > absl::ToInt64Microseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Microseconds(x) > d1; + // CHECK-FIXES: b = absl::Microseconds(x) > d1; b = x >= absl::ToInt64Milliseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Milliseconds(x) >= d1; + // CHECK-FIXES: b = absl::Milliseconds(x) >= d1; b = x == absl::ToInt64Nanoseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Nanoseconds(x) == d1; + // CHECK-FIXES: b = absl::Nanoseconds(x) == d1; b = x == absl::ToInt64Seconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(x) == d1; + // CHECK-FIXES: b = absl::Seconds(x) == d1; b = x <= absl::ToInt64Minutes(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Minutes(x) <= d1; + // CHECK-FIXES: b = absl::Minutes(x) <= d1; b = x < absl::ToInt64Hours(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Hours(x) < d1; + // CHECK-FIXES: b = absl::Hours(x) < d1; // Other abseil-duration checks folded into this one b = static_cast(5) > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(5) > d1; + // CHECK-FIXES: b = absl::Seconds(5) > d1; b = double(5) > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(5) > d1; + // CHECK-FIXES: b = absl::Seconds(5) > d1; b = float(5) > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(5) > d1; + // CHECK-FIXES: b = absl::Seconds(5) > d1; b = ((double)5) > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(5) > d1; + // CHECK-FIXES: b = absl::Seconds(5) > d1; b = 5.0 > absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Seconds(5) > d1; + // CHECK-FIXES: b = absl::Seconds(5) > d1; // A long expression bool some_condition; @@ -125,20 +125,20 @@ void f() { int y; b = (y + 5) * 10 > absl::ToDoubleMilliseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: absl::Milliseconds((y + 5) * 10) > d1; + // CHECK-FIXES: b = absl::Milliseconds((y + 5) * 10) > d1; // We should still transform the expression inside this macro invocation #define VALUE_IF(v, e) v ? (e) : 0 int a = VALUE_IF(1, 5 > absl::ToDoubleSeconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:23: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: VALUE_IF(1, absl::Seconds(5) > d1); + // CHECK-FIXES: int a = VALUE_IF(1, absl::Seconds(5) > d1); #undef VALUE_IF #define VALUE_IF_2(e) (e) #define VALUE_IF(v, e) v ? VALUE_IF_2(e) : VALUE_IF_2(0) int a2 = VALUE_IF(1, 5 > absl::ToDoubleSeconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:24: warning: perform comparison in the duration domain [abseil-duration-comparison] - // CHECK-FIXES: VALUE_IF(1, absl::Seconds(5) > d1); + // CHECK-FIXES: int a2 = VALUE_IF(1, absl::Seconds(5) > d1); #undef VALUE_IF #undef VALUE_IF_2 diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp index 368b9d63e0ec7..b5183a98e0f2d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-conversion-cast %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-conversion-cast %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -9,56 +9,56 @@ void f() { i = static_cast(absl::ToDoubleHours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Hours(d1); + // CHECK-FIXES: i = absl::ToInt64Hours(d1); x = static_cast(absl::ToInt64Hours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleHours(d1); + // CHECK-FIXES: x = absl::ToDoubleHours(d1); i = static_cast(absl::ToDoubleMinutes(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Minutes(d1); + // CHECK-FIXES: i = absl::ToInt64Minutes(d1); x = static_cast(absl::ToInt64Minutes(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMinutes(d1); + // CHECK-FIXES: x = absl::ToDoubleMinutes(d1); i = static_cast(absl::ToDoubleSeconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Seconds(d1); + // CHECK-FIXES: i = absl::ToInt64Seconds(d1); x = static_cast(absl::ToInt64Seconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleSeconds(d1); + // CHECK-FIXES: x = absl::ToDoubleSeconds(d1); i = static_cast(absl::ToDoubleMilliseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Milliseconds(d1); + // CHECK-FIXES: i = absl::ToInt64Milliseconds(d1); x = static_cast(absl::ToInt64Milliseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMilliseconds(d1); + // CHECK-FIXES: x = absl::ToDoubleMilliseconds(d1); i = static_cast(absl::ToDoubleMicroseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Microseconds(d1); + // CHECK-FIXES: i = absl::ToInt64Microseconds(d1); x = static_cast(absl::ToInt64Microseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMicroseconds(d1); + // CHECK-FIXES: x = absl::ToDoubleMicroseconds(d1); i = static_cast(absl::ToDoubleNanoseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Nanoseconds(d1); + // CHECK-FIXES: i = absl::ToInt64Nanoseconds(d1); x = static_cast(absl::ToInt64Nanoseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleNanoseconds(d1); + // CHECK-FIXES: x = absl::ToDoubleNanoseconds(d1); // Functional-style casts i = int(absl::ToDoubleHours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Hours(d1); + // CHECK-FIXES: i = absl::ToInt64Hours(d1); x = float(absl::ToInt64Microseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMicroseconds(d1); + // CHECK-FIXES: x = absl::ToDoubleMicroseconds(d1); // C-style casts i = (int) absl::ToDoubleHours(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Hours(d1); + // CHECK-FIXES: i = absl::ToInt64Hours(d1); x = (float) absl::ToInt64Microseconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMicroseconds(d1); + // CHECK-FIXES: x = absl::ToDoubleMicroseconds(d1); // Type aliasing typedef int FancyInt; @@ -66,17 +66,17 @@ void f() { FancyInt j = static_cast(absl::ToDoubleHours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:16: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToInt64Hours(d1); + // CHECK-FIXES: FancyInt j = absl::ToInt64Hours(d1); FancyFloat k = static_cast(absl::ToInt64Microseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:18: warning: duration should be converted directly to a floating-point number rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: absl::ToDoubleMicroseconds(d1); + // CHECK-FIXES: FancyFloat k = absl::ToDoubleMicroseconds(d1); // Macro handling // We want to transform things in macro arguments #define EXTERNAL(x) (x) + 5 i = EXTERNAL(static_cast(absl::ToDoubleSeconds(d1))); // CHECK-MESSAGES: [[@LINE-1]]:16: warning: duration should be converted directly to an integer rather than through a type cast [abseil-duration-conversion-cast] - // CHECK-FIXES: EXTERNAL(absl::ToInt64Seconds(d1)); + // CHECK-FIXES: i = EXTERNAL(absl::ToInt64Seconds(d1)); #undef EXTERNAL // We don't want to transform this which get split across macro boundaries diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp index 2f38dbfe9778d..9daaa7275fabd 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-factory-float %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-factory-float %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -7,26 +7,26 @@ void ConvertFloatTest() { d = absl::Seconds(60.0); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(60); + // CHECK-FIXES: d = absl::Seconds(60); d = absl::Minutes(300.0); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Minutes [abseil-duration-factory-float] - // CHECK-FIXES: absl::Minutes(300); + // CHECK-FIXES: d = absl::Minutes(300); d = absl::Milliseconds(1e2); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Milliseconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Milliseconds(100); + // CHECK-FIXES: d = absl::Milliseconds(100); d = absl::Seconds(3.0f); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(3); + // CHECK-FIXES: d = absl::Seconds(3); d = absl::Seconds(3.); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(3); + // CHECK-FIXES: d = absl::Seconds(3); d = absl::Seconds(0x3.p0); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(3); + // CHECK-FIXES: d = absl::Seconds(3); d = absl::Seconds(0x3.p1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(6); + // CHECK-FIXES: d = absl::Seconds(6); // Ignored expressions @@ -65,7 +65,7 @@ void InTemplate() { d = absl::Minutes(1.0); // 2 // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Minutes [abseil-duration-factory-float] - // CHECK-FIXES: absl::Minutes(1); // 2 + // CHECK-FIXES: d = absl::Minutes(1); // 2 } void Instantiate() { @@ -78,27 +78,27 @@ void ConvertCastTest() { d = absl::Seconds(static_cast(5)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(5); + // CHECK-FIXES: d = absl::Seconds(5); d = absl::Minutes(static_cast(5)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Minutes [abseil-duration-factory-float] - // CHECK-FIXES: absl::Minutes(5); + // CHECK-FIXES: d = absl::Minutes(5); d = absl::Seconds((double) 5); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(5); + // CHECK-FIXES: d = absl::Seconds(5); d = absl::Minutes((float) 5); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Minutes [abseil-duration-factory-float] - // CHECK-FIXES: absl::Minutes(5); + // CHECK-FIXES: d = absl::Minutes(5); d = absl::Seconds(double(5)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Seconds [abseil-duration-factory-float] - // CHECK-FIXES: absl::Seconds(5); + // CHECK-FIXES: d = absl::Seconds(5); d = absl::Minutes(float(5)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: use the integer version of absl::Minutes [abseil-duration-factory-float] - // CHECK-FIXES: absl::Minutes(5); + // CHECK-FIXES: d = absl::Minutes(5); // This should not be flagged d = absl::Seconds(static_cast(5.0)); diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp index dd5f808f5a4c3..7213f5ce45f8e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-factory-scale %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -11,87 +11,87 @@ void ScaleTest() { // Zeroes d = absl::Hours(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Minutes(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Milliseconds(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Microseconds(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Nanoseconds(0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(0.0); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(0x0.000001p-126f); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(int{0}); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(int64_t{0}); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); d = absl::Seconds(float{0}); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use ZeroDuration() for zero-length time intervals [abseil-duration-factory-scale] - // CHECK-FIXES: absl::ZeroDuration(); + // CHECK-FIXES: d = absl::ZeroDuration(); // Fold seconds into minutes d = absl::Seconds(30 * 60); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Minutes(30); + // CHECK-FIXES: d = absl::Minutes(30); d = absl::Seconds(60 * 30); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Minutes(30); + // CHECK-FIXES: d = absl::Minutes(30); // Try a few more exotic multiplications d = absl::Seconds(60 * 30 * 60); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Minutes(60 * 30); + // CHECK-FIXES: d = absl::Minutes(60 * 30); d = absl::Seconds(1e-3 * 30); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Milliseconds(30); + // CHECK-FIXES: d = absl::Milliseconds(30); d = absl::Milliseconds(30 * 1000); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Seconds(30); + // CHECK-FIXES: d = absl::Seconds(30); d = absl::Milliseconds(30 * 0.001); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Microseconds(30); + // CHECK-FIXES: d = absl::Microseconds(30); // Multiple steps d = absl::Seconds(5 * 3600); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Hours(5); + // CHECK-FIXES: d = absl::Hours(5); d = absl::Microseconds(5 * 1e6); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Seconds(5); + // CHECK-FIXES: d = absl::Seconds(5); d = absl::Seconds(5 * 1e-6); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Microseconds(5); + // CHECK-FIXES: d = absl::Microseconds(5); d = absl::Microseconds(5 * 1000000); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Seconds(5); + // CHECK-FIXES: d = absl::Seconds(5); // Division d = absl::Hours(30 / 60.); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Minutes(30); + // CHECK-FIXES: d = absl::Minutes(30); d = absl::Seconds(30 / 1000.); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Milliseconds(30); + // CHECK-FIXES: d = absl::Milliseconds(30); d = absl::Milliseconds(30 / 1e3); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Microseconds(30); + // CHECK-FIXES: d = absl::Microseconds(30); d = absl::Seconds(30 / 1e6); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: internal duration scaling can be removed [abseil-duration-factory-scale] - // CHECK-FIXES: absl::Microseconds(30); + // CHECK-FIXES: d = absl::Microseconds(30); // None of these should trigger the check d = absl::Seconds(60); diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp index 167258e32599d..53b558b279367 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-subtraction %t -- -- -I %S/Inputs +// RUN: %check_clang_tidy %s abseil-duration-subtraction %t -- -- -I %S/Inputs #include "absl/time/time.h" @@ -8,34 +8,34 @@ void f() { x = absl::ToDoubleSeconds(d) - 1.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1)) + // CHECK-FIXES: x = absl::ToDoubleSeconds(d - absl::Seconds(1)); x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(d - d1); + // CHECK-FIXES: x = absl::ToDoubleSeconds(d - d1); x = absl::ToDoubleSeconds(d) - 6.5 - 8.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(6.5)) - 8.0; + // CHECK-FIXES: x = absl::ToDoubleSeconds(d - absl::Seconds(6.5)) - 8.0; x = absl::ToDoubleHours(d) - 1.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleHours(d - absl::Hours(1)) + // CHECK-FIXES: x = absl::ToDoubleHours(d - absl::Hours(1)); x = absl::ToDoubleMinutes(d) - 1; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleMinutes(d - absl::Minutes(1)) + // CHECK-FIXES: x = absl::ToDoubleMinutes(d - absl::Minutes(1)); x = absl::ToDoubleMilliseconds(d) - 9; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleMilliseconds(d - absl::Milliseconds(9)) + // CHECK-FIXES: x = absl::ToDoubleMilliseconds(d - absl::Milliseconds(9)); x = absl::ToDoubleMicroseconds(d) - 9; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleMicroseconds(d - absl::Microseconds(9)) + // CHECK-FIXES: x = absl::ToDoubleMicroseconds(d - absl::Microseconds(9)); x = absl::ToDoubleNanoseconds(d) - 42; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleNanoseconds(d - absl::Nanoseconds(42)) + // CHECK-FIXES: x = absl::ToDoubleNanoseconds(d - absl::Nanoseconds(42)); // We can rewrite the argument of the duration conversion #define THIRTY absl::Seconds(30) x = absl::ToDoubleSeconds(THIRTY) - 1.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(THIRTY - absl::Seconds(1)) + // CHECK-FIXES: x = absl::ToDoubleSeconds(THIRTY - absl::Seconds(1)); #undef THIRTY // Some other contexts @@ -46,10 +46,10 @@ void f() { // A nested occurrence x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(5)); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(5)) + // CHECK-FIXES: x = absl::ToDoubleSeconds(d - absl::Seconds(5)); x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(absl::ToDoubleSeconds(d1))); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction] - // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1))) + // CHECK-FIXES: x = absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1))); // These should not match x = 5 - 6; diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp index f4c69c5adc440..92891b66365ed 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs +// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs #include "absl/time/time.h" @@ -8,86 +8,86 @@ void f() { // Floating point d2 = absl::Hours(absl::ToDoubleHours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Minutes(absl::ToDoubleMinutes(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Seconds(absl::ToDoubleSeconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Milliseconds(absl::ToDoubleMilliseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Microseconds(absl::ToDoubleMicroseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Nanoseconds(absl::ToDoubleNanoseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; // Integer point d2 = absl::Hours(absl::ToInt64Hours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Minutes(absl::ToInt64Minutes(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Seconds(absl::ToInt64Seconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Milliseconds(absl::ToInt64Milliseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Microseconds(absl::ToInt64Microseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Nanoseconds(absl::ToInt64Nanoseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Hours(d1 / absl::Hours(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Minutes(d1 / absl::Minutes(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Seconds(d1 / absl::Seconds(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Milliseconds(d1 / absl::Milliseconds(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Microseconds(d1 / absl::Microseconds(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Nanoseconds(d1 / absl::Nanoseconds(1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Hours(absl::FDivDuration(d1, absl::Hours(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Minutes(absl::FDivDuration(d1, absl::Minutes(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Seconds(absl::FDivDuration(d1, absl::Seconds(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Milliseconds(absl::FDivDuration(d1, absl::Milliseconds(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Microseconds(absl::FDivDuration(d1, absl::Microseconds(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; d2 = absl::Nanoseconds(absl::FDivDuration(d1, absl::Nanoseconds(1))); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 + // CHECK-FIXES: d2 = d1; // As macro argument #define PLUS_FIVE_S(x) x + absl::Seconds(5) d2 = PLUS_FIVE_S(absl::Seconds(absl::ToInt64Seconds(d1))); // CHECK-MESSAGES: [[@LINE-1]]:20: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: PLUS_FIVE_S(d1) + // CHECK-FIXES: d2 = PLUS_FIVE_S(d1); #undef PLUS_FIVE_S // Split by macro: should not change @@ -103,40 +103,40 @@ void f() { // Multiplication d2 = absl::Nanoseconds(absl::ToDoubleNanoseconds(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Microseconds(absl::ToInt64Microseconds(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Milliseconds(absl::ToDoubleMilliseconds(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Seconds(absl::ToInt64Seconds(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Minutes(absl::ToDoubleMinutes(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Hours(absl::ToInt64Hours(d1) * 2); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = d1 * 2 + // CHECK-FIXES: d2 = d1 * 2; d2 = absl::Nanoseconds(2 * absl::ToDoubleNanoseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; d2 = absl::Microseconds(2 * absl::ToInt64Microseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; d2 = absl::Milliseconds(2 * absl::ToDoubleMilliseconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; d2 = absl::Seconds(2 * absl::ToInt64Seconds(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; d2 = absl::Minutes(2 * absl::ToDoubleMinutes(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; d2 = absl::Hours(2 * absl::ToInt64Hours(d1)); // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion] - // CHECK-FIXES: d2 = 2 * d1 + // CHECK-FIXES: d2 = 2 * d1; // These should not match d2 = absl::Seconds(absl::ToDoubleMilliseconds(d1)); diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp index b5e866c3043fd..8fa1b1e1ad906 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers +// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers #include namespace absl { @@ -69,7 +69,7 @@ using absl::StrCat; void Positives() { std::string S = StrCat(1, StrCat("A", StrCat(1.1))); // CHECK-MESSAGES: [[@LINE-1]]:19: warning: multiple calls to 'absl::StrCat' can be flattened into a single call - // CHECK-FIXES: string S = StrCat(1, "A", 1.1); + // CHECK-FIXES: std::string S = StrCat(1, "A", 1.1); S = StrCat(StrCat(StrCat(StrCat(StrCat(1))))); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: multiple calls to 'absl::StrCat' can be flattened into a single call diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/str-cat-append.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/str-cat-append.cpp index 9a2585da5b277..90936fbb12a1f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/str-cat-append.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/str-cat-append.cpp @@ -97,7 +97,7 @@ void Bar() { // CHECK-MESSAGES: [[@LINE-1]]:3: warning: call to 'absl::StrCat' has no effect A = StrCat(A, B); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty -// CHECK-FIXES: {{^}} absl::StrAppend(&A, B); +// CHECK-FIXES: absl::StrAppend(&A, B); B = StrCat(A, B); #define M(X) X = StrCat(X, A) @@ -117,7 +117,7 @@ void OutsideAbsl() { std::string A, B; A = absl::StrCat(A, B); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty -// CHECK-FIXES: {{^}} absl::StrAppend(&A, B); +// CHECK-FIXES: absl::StrAppend(&A, B); } void OutsideUsingAbsl() { @@ -125,5 +125,5 @@ void OutsideUsingAbsl() { using absl::StrCat; A = StrCat(A, B); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: call 'absl::StrAppend' instead of 'absl::StrCat' when appending to a string to avoid a performance penalty -// CHECK-FIXES: {{^}} absl::StrAppend(&A, B); +// CHECK-FIXES: absl::StrAppend(&A, B); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp index bb9ba9918a1ba..c5d1f178e48b0 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp @@ -70,41 +70,41 @@ void basic_tests() { std::string ss; ss.find("a") == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of find() == npos - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(ss, "a"); ss.find("a") != std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of find() != npos - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ss, "a"); std::string::npos != ss.find("a"); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ss, "a"); std::string_view ssv; ssv.find("a") == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, "a"); ssv.find("a") != std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ssv, "a"); std::string_view::npos != ssv.find("a"); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ssv, "a"); absl::string_view asv; asv.find("a") == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(asv, "a"); asv.find("a") != absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(asv, "a"); absl::string_view::npos != asv.find("a"); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(asv, "a"); } // Confirms that it works even if you mix-and-match the type for find and for @@ -115,29 +115,29 @@ void mismatched_npos() { std::string ss; ss.find("a") == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(ss, "a"); ss.find("a") != absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ss, "a"); std::string_view ssv; ssv.find("a") == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, "a"); ssv.find("a") != std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(ssv, "a"); absl::string_view asv; asv.find("a") == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, "a");{{$}} + // CHECK-FIXES: !absl::StrContains(asv, "a"); asv.find("a") != std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, "a");{{$}} + // CHECK-FIXES: absl::StrContains(asv, "a"); } // Confirms that it works even when the needle or the haystack are more @@ -146,41 +146,41 @@ void subexpression_tests() { std::string ss, ss2; foo_ss(ss).find(ss2) == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(foo_ss(ss), ss2);{{$}} + // CHECK-FIXES: !absl::StrContains(foo_ss(ss), ss2); ss.find(foo_ss(ss2)) != std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ss, foo_ss(ss2));{{$}} + // CHECK-FIXES: absl::StrContains(ss, foo_ss(ss2)); foo_ss(bar_ss()).find(foo_ss(ss2)) != std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(foo_ss(bar_ss()), foo_ss(ss2));{{$}} + // CHECK-FIXES: absl::StrContains(foo_ss(bar_ss()), foo_ss(ss2)); std::string_view ssv, ssv2; foo_ssv(ssv).find(ssv2) == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(foo_ssv(ssv), ssv2);{{$}} + // CHECK-FIXES: !absl::StrContains(foo_ssv(ssv), ssv2); ssv.find(foo_ssv(ssv2)) != std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(ssv, foo_ssv(ssv2));{{$}} + // CHECK-FIXES: absl::StrContains(ssv, foo_ssv(ssv2)); foo_ssv(bar_ssv()).find(foo_ssv(ssv2)) != std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(foo_ssv(bar_ssv()), foo_ssv(ssv2));{{$}} + // CHECK-FIXES: absl::StrContains(foo_ssv(bar_ssv()), foo_ssv(ssv2)); absl::string_view asv, asv2; foo_asv(asv).find(asv2) == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(foo_asv(asv), asv2);{{$}} + // CHECK-FIXES: !absl::StrContains(foo_asv(asv), asv2); asv.find(foo_asv(asv2)) != absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(asv, foo_asv(asv2));{{$}} + // CHECK-FIXES: absl::StrContains(asv, foo_asv(asv2)); foo_asv(bar_asv()).find(foo_asv(asv2)) != absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}absl::StrContains(foo_asv(bar_asv()), foo_asv(asv2));{{$}} + // CHECK-FIXES: absl::StrContains(foo_asv(bar_asv()), foo_asv(asv2)); } // Confirms that it works with string literal, char* and const char* parameters. @@ -191,58 +191,58 @@ void string_literal_and_char_ptr_tests() { std::string ss; ss.find("c") == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, "c");{{$}} + // CHECK-FIXES: !absl::StrContains(ss, "c"); ss.find(c) == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, c);{{$}} + // CHECK-FIXES: !absl::StrContains(ss, c); ss.find(cc) == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, cc);{{$}} + // CHECK-FIXES: !absl::StrContains(ss, cc); std::string_view ssv; ssv.find("c") == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, "c");{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, "c"); ssv.find(c) == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, c);{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, c); ssv.find(cc) == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, cc);{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, cc); absl::string_view asv; asv.find("c") == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, "c");{{$}} + // CHECK-FIXES: !absl::StrContains(asv, "c"); asv.find(c) == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, c);{{$}} + // CHECK-FIXES: !absl::StrContains(asv, c); asv.find(cc) == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, cc);{{$}} + // CHECK-FIXES: !absl::StrContains(asv, cc); } void char_param_tests() { std::string ss; ss.find('c') == std::string::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ss, 'c');{{$}} + // CHECK-FIXES: !absl::StrContains(ss, 'c'); std::string_view ssv; ssv.find('c') == std::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(ssv, 'c');{{$}} + // CHECK-FIXES: !absl::StrContains(ssv, 'c'); absl::string_view asv; asv.find('c') == absl::string_view::npos; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use !absl::StrContains instead of - // CHECK-FIXES: {{^[[:space:]]*}}!absl::StrContains(asv, 'c');{{$}} + // CHECK-FIXES: !absl::StrContains(asv, 'c'); } #define FOO(a, b, c, d) ((a).find(b) == std::string::npos ? (c) : (d)) diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/time-comparison.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/time-comparison.cpp index 4de43ec56436e..ad3ce4cb68396 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/time-comparison.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/time-comparison.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s abseil-time-comparison %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s abseil-time-comparison %t -- -- -I%S/Inputs #include "absl/time/time.h" @@ -11,67 +11,67 @@ void f() { // Check against the RHS b = x > absl::ToUnixSeconds(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) > t1; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) > t1; b = x >= absl::ToUnixSeconds(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) >= t1; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) >= t1; b = x == absl::ToUnixSeconds(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) == t1; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) == t1; b = x <= absl::ToUnixSeconds(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) <= t1; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) <= t1; b = x < absl::ToUnixSeconds(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) < t1; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) < t1; b = x == absl::ToUnixSeconds(t1 - d2); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixSeconds(x) == t1 - d2; + // CHECK-FIXES: b = absl::FromUnixSeconds(x) == t1 - d2; b = absl::ToUnixSeconds(t1) > absl::ToUnixSeconds(t2); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 > t2; + // CHECK-FIXES: b = t1 > t2; // Check against the LHS b = absl::ToUnixSeconds(t1) < x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 < absl::FromUnixSeconds(x); + // CHECK-FIXES: b = t1 < absl::FromUnixSeconds(x); b = absl::ToUnixSeconds(t1) <= x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 <= absl::FromUnixSeconds(x); + // CHECK-FIXES: b = t1 <= absl::FromUnixSeconds(x); b = absl::ToUnixSeconds(t1) == x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 == absl::FromUnixSeconds(x); + // CHECK-FIXES: b = t1 == absl::FromUnixSeconds(x); b = absl::ToUnixSeconds(t1) >= x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 >= absl::FromUnixSeconds(x); + // CHECK-FIXES: b = t1 >= absl::FromUnixSeconds(x); b = absl::ToUnixSeconds(t1) > x; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 > absl::FromUnixSeconds(x); + // CHECK-FIXES: b = t1 > absl::FromUnixSeconds(x); // Comparison against zero b = absl::ToUnixSeconds(t1) < 0.0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 < absl::UnixEpoch(); + // CHECK-FIXES: b = t1 < absl::UnixEpoch(); b = absl::ToUnixSeconds(t1) < 0; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: t1 < absl::UnixEpoch(); + // CHECK-FIXES: b = t1 < absl::UnixEpoch(); // Scales other than Seconds b = x > absl::ToUnixMicros(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixMicros(x) > t1; + // CHECK-FIXES: b = absl::FromUnixMicros(x) > t1; b = x >= absl::ToUnixMillis(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixMillis(x) >= t1; + // CHECK-FIXES: b = absl::FromUnixMillis(x) >= t1; b = x == absl::ToUnixNanos(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixNanos(x) == t1; + // CHECK-FIXES: b = absl::FromUnixNanos(x) == t1; b = x <= absl::ToUnixMinutes(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixMinutes(x) <= t1; + // CHECK-FIXES: b = absl::FromUnixMinutes(x) <= t1; b = x < absl::ToUnixHours(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixHours(x) < t1; + // CHECK-FIXES: b = absl::FromUnixHours(x) < t1; // A long expression bool some_condition; @@ -88,20 +88,20 @@ void f() { int y; b = (y + 5) * 10 > absl::ToUnixMillis(t1); // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: absl::FromUnixMillis((y + 5) * 10) > t1; + // CHECK-FIXES: b = absl::FromUnixMillis((y + 5) * 10) > t1; // We should still transform the expression inside this macro invocation #define VALUE_IF(v, e) v ? (e) : 0 int a = VALUE_IF(1, 5 > absl::ToUnixSeconds(t1)); // CHECK-MESSAGES: [[@LINE-1]]:23: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: VALUE_IF(1, absl::FromUnixSeconds(5) > t1); + // CHECK-FIXES: int a = VALUE_IF(1, absl::FromUnixSeconds(5) > t1); #undef VALUE_IF #define VALUE_IF_2(e) (e) #define VALUE_IF(v, e) v ? VALUE_IF_2(e) : VALUE_IF_2(0) int a2 = VALUE_IF(1, 5 > absl::ToUnixSeconds(t1)); // CHECK-MESSAGES: [[@LINE-1]]:24: warning: perform comparison in the time domain [abseil-time-comparison] - // CHECK-FIXES: VALUE_IF(1, absl::FromUnixSeconds(5) > t1); + // CHECK-FIXES: int a2 = VALUE_IF(1, absl::FromUnixSeconds(5) > t1); #undef VALUE_IF #undef VALUE_IF_2 diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/time-subtraction.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/time-subtraction.cpp index 82014e8f46a5f..dde0681a846f5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/time-subtraction.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/time-subtraction.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11-or-later %s abseil-time-subtraction %t -- -- -I %S/Inputs +// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- -- -I %S/Inputs #include "absl/time/time.h" @@ -89,7 +89,7 @@ void f() { #define SECONDS(z) absl::Seconds(z) d = SECONDS(x - absl::ToUnixSeconds(t)); // CHECK-MESSAGES: [[@LINE-1]]:15: warning: perform subtraction in the time domain [abseil-time-subtraction] - // CHECK-FIXES: SECONDS(absl::ToInt64Seconds(absl::FromUnixSeconds(x) - t)) + // CHECK-FIXES: d = SECONDS(absl::ToInt64Seconds(absl::FromUnixSeconds(x) - t)); #undef SECONDS } diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/upgrade-duration-conversions.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/upgrade-duration-conversions.cpp index b5dfb4f4d73e8..67fbe3fc08a5e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/upgrade-duration-conversions.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/upgrade-duration-conversions.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11-or-later %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs using int64_t = long long; @@ -49,22 +49,22 @@ void arithmeticOperatorBasicPositive() { ConvertibleTo c; d *= (c + c) * c + c; // CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: d *= static_cast((c + c) * c + c) + // CHECK-FIXES: d *= static_cast((c + c) * c + c); d /= (c + c) * c + c; // CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: d /= static_cast((c + c) * c + c) + // CHECK-FIXES: d /= static_cast((c + c) * c + c); d = d * c * c; // CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead // CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: d = d * static_cast(c) * static_cast(c) + // CHECK-FIXES: d = d * static_cast(c) * static_cast(c); d = c * d * c; // CHECK-MESSAGES: [[@LINE-1]]:7: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead // CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: d = static_cast(c) * d * static_cast(c) + // CHECK-FIXES: d = static_cast(c) * d * static_cast(c); d = d / c * c; // CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead // CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: d = d / static_cast(c) * static_cast(c) + // CHECK-FIXES: d = d / static_cast(c) * static_cast(c); } void arithmeticOperatorBasicNegative() { @@ -407,7 +407,7 @@ template void factoryTemplateAndMacro() { // CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead (void)absl::Nanoseconds(CONVERTIBLE_TMP); // CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: (void)absl::Nanoseconds(static_cast(CONVERTIBLE_TMP)) + // CHECK-FIXES: (void)absl::Nanoseconds(static_cast(CONVERTIBLE_TMP)); T_CALL_FACTORTY_INSIDE_MACRO; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead } @@ -424,7 +424,7 @@ void factoryInMacros() { // CHECK-FIXES: (void)absl::Nanoseconds(static_cast(FUNCTION_MACRO(ConvertibleTo()))); (void)absl::Nanoseconds(CONVERTIBLE_TMP); // CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead - // CHECK-FIXES: (void)absl::Nanoseconds(static_cast(CONVERTIBLE_TMP)) + // CHECK-FIXES: (void)absl::Nanoseconds(static_cast(CONVERTIBLE_TMP)); ONLY_WARN_INSIDE_MACRO_FACTORY; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead factoryTemplateAndMacro>(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align.cpp index 9aaca68b363a1..6b5b946136f30 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s altera-struct-pack-align %t -- -header-filter=.* +// RUN: %check_clang_tidy %s altera-struct-pack-align %t -- -header-filter=.* // Struct needs both alignment and packing struct error { @@ -10,8 +10,7 @@ struct error { // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((packed))" to reduce the amount of padding applied to struct 'error' // CHECK-MESSAGES: :[[@LINE-7]]:8: warning: accessing fields in struct 'error' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-8]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error' to 16 bytes -// CHECK-FIXES: __attribute__((packed)) -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16))); // Struct is explicitly packed, but needs alignment struct error_packed { @@ -21,7 +20,7 @@ struct error_packed { } __attribute__((packed)); // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'error_packed' is inefficient due to poor alignment; currently aligned to 1 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'error_packed' to 16 bytes -// CHECK-FIXES: __attribute__((aligned(16))) +// CHECK-FIXES: } __attribute__((aligned(16))) __attribute__((packed)); // Struct is properly packed, but needs alignment struct align_only { @@ -34,7 +33,7 @@ struct align_only { }; // CHECK-MESSAGES: :[[@LINE-8]]:8: warning: accessing fields in struct 'align_only' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-9]]:8: note: use "__attribute__((aligned(16)))" to align struct 'align_only' to 16 bytes -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((aligned(16))); // Struct is perfectly packed but wrongly aligned struct bad_align { @@ -44,7 +43,7 @@ struct bad_align { } __attribute__((packed)) __attribute__((aligned(8))); // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align' to 16 bytes -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16))); struct bad_align2 { char a; @@ -53,7 +52,7 @@ struct bad_align2 { } __attribute__((packed)) __attribute__((aligned(32))); // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align2' is inefficient due to poor alignment; currently aligned to 32 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align2' to 16 bytes -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16))); struct bad_align3 { char a; @@ -62,7 +61,7 @@ struct bad_align3 { } __attribute__((packed)) __attribute__((aligned(4))); // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: accessing fields in struct 'bad_align3' is inefficient due to poor alignment; currently aligned to 4 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((aligned(16)))" to align struct 'bad_align3' to 16 bytes -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16))); // Struct is both perfectly packed and aligned struct success { @@ -116,5 +115,4 @@ struct ContainsStructWithNoFields2 { // CHECK-MESSAGES: :[[@LINE-6]]:8: note: use "__attribute__((packed))" to reduce the amount of padding applied to struct 'ContainsStructWithNoFields2' // CHECK-MESSAGES: :[[@LINE-7]]:8: warning: accessing fields in struct 'ContainsStructWithNoFields2' is inefficient due to poor alignment; currently aligned to 8 bytes, but recommended alignment is 16 bytes [altera-struct-pack-align] // CHECK-MESSAGES: :[[@LINE-8]]:8: note: use "__attribute__((aligned(16)))" to align struct 'ContainsStructWithNoFields2' to 16 bytes -// CHECK-FIXES: __attribute__((packed)) -// CHECK-FIXES: __attribute__((aligned(16))); +// CHECK-FIXES: } __attribute__((packed)) __attribute__((aligned(16))); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp index b2c299b46d0a3..d1d77d35392c8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s android-cloexec-memfd-create %t +// RUN: %check_clang_tidy %s android-cloexec-memfd-create %t #define MFD_ALLOW_SEALING 1 #define __O_CLOEXEC 3 @@ -17,19 +17,19 @@ extern "C" int memfd_create(const char *name, unsigned int flags); void a() { memfd_create(NULL, MFD_ALLOW_SEALING); // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: 'memfd_create' should use MFD_CLOEXEC where possible [android-cloexec-memfd-create] - // CHECK-FIXES: memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC) + // CHECK-FIXES: memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC); TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING)); // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: 'memfd_create' - // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC)) + // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC)); } void f() { memfd_create(NULL, 3); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'memfd_create' - // CHECK-FIXES: memfd_create(NULL, 3 | MFD_CLOEXEC) + // CHECK-FIXES: memfd_create(NULL, 3 | MFD_CLOEXEC); TEMP_FAILURE_RETRY(memfd_create(NULL, 3)); // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: 'memfd_create' - // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, 3 | MFD_CLOEXEC)) + // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, 3 | MFD_CLOEXEC)); int flag = 3; memfd_create(NULL, flag); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-open.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-open.cpp index 651e469721284..46e30ab3557b8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-open.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-open.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s android-cloexec-open %t +// RUN: %check_clang_tidy %s android-cloexec-open %t #define O_RDWR 1 #define O_EXCL 2 @@ -19,67 +19,67 @@ extern "C" int openat(int dirfd, const char *pathname, int flags, ...); void a() { open("filename", O_RDWR); // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'open' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: open("filename", O_RDWR | O_CLOEXEC); TEMP_FAILURE_RETRY(open("filename", O_RDWR)); // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'open' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_CLOEXEC)); open("filename", O_RDWR | O_EXCL); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: 'open' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: open("filename", O_RDWR | O_EXCL | O_CLOEXEC); TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_EXCL)); // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: 'open' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open("filename", O_RDWR | O_EXCL | O_CLOEXEC)); } void b() { open64("filename", O_RDWR); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: 'open64' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: open64("filename", O_RDWR | O_CLOEXEC); TEMP_FAILURE_RETRY(open64("filename", O_RDWR)); // CHECK-MESSAGES: :[[@LINE-1]]:47: warning: 'open64' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_CLOEXEC)); open64("filename", O_RDWR | O_EXCL); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'open64' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: open64("filename", O_RDWR | O_EXCL | O_CLOEXEC); TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_EXCL)); // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: 'open64' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open64("filename", O_RDWR | O_EXCL | O_CLOEXEC)); } void c() { openat(0, "filename", O_RDWR); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'openat' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: openat(0, "filename", O_RDWR | O_CLOEXEC); TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR)); // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: 'openat' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_CLOEXEC)); openat(0, "filename", O_RDWR | O_EXCL); // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: 'openat' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: openat(0, "filename", O_RDWR | O_EXCL | O_CLOEXEC); TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_EXCL)); // CHECK-MESSAGES: :[[@LINE-1]]:59: warning: 'openat' should use O_CLOEXEC where - // CHECK-FIXES: O_RDWR | O_EXCL | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(openat(0, "filename", O_RDWR | O_EXCL | O_CLOEXEC)); } void f() { open("filename", 3); // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'open' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: open("filename", 3 | O_CLOEXEC); TEMP_FAILURE_RETRY(open("filename", 3)); // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: 'open' should use O_CLOEXEC where - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open("filename", 3 | O_CLOEXEC)); open64("filename", 3); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'open64' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: open64("filename", 3 | O_CLOEXEC); TEMP_FAILURE_RETRY(open64("filename", 3)); // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: 'open64' should use O_CLOEXEC where - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(open64("filename", 3 | O_CLOEXEC)); openat(0, "filename", 3); // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: 'openat' should use O_CLOEXEC where possible [android-cloexec-open] - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: openat(0, "filename", 3 | O_CLOEXEC); TEMP_FAILURE_RETRY(openat(0, "filename", 3)); // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: 'openat' should use O_CLOEXEC where - // CHECK-FIXES: 3 | O_CLOEXEC + // CHECK-FIXES: TEMP_FAILURE_RETRY(openat(0, "filename", 3 | O_CLOEXEC)); int flag = 3; open("filename", flag); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-socket.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-socket.cpp index d4d58640f0eea..3a25a9360bbc6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-socket.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-socket.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s android-cloexec-socket %t +// RUN: %check_clang_tidy %s android-cloexec-socket %t #define SOCK_STREAM 1 #define SOCK_DGRAM 2 @@ -17,25 +17,25 @@ extern "C" int socket(int domain, int type, int protocol); void a() { socket(0, SOCK_STREAM, 0); // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'socket' should use SOCK_CLOEXEC where possible [android-cloexec-socket] - // CHECK-FIXES: socket(0, SOCK_STREAM | SOCK_CLOEXEC, 0) + // CHECK-FIXES: socket(0, SOCK_STREAM | SOCK_CLOEXEC, 0); TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM, 0)); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: 'socket' - // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM | SOCK_CLOEXEC, 0)) + // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM | SOCK_CLOEXEC, 0)); socket(0, SOCK_STREAM | SOCK_DGRAM, 0); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'socket' - // CHECK-FIXES: socket(0, SOCK_STREAM | SOCK_DGRAM | SOCK_CLOEXEC, 0) + // CHECK-FIXES: socket(0, SOCK_STREAM | SOCK_DGRAM | SOCK_CLOEXEC, 0); TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM | SOCK_DGRAM, 0)); // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: 'socket' - // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM | SOCK_DGRAM | SOCK_CLOEXEC, 0)) + // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM | SOCK_DGRAM | SOCK_CLOEXEC, 0)); } void f() { socket(0, 3, 0); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'socket' - // CHECK-FIXES: socket(0, 3 | SOCK_CLOEXEC, 0) + // CHECK-FIXES: socket(0, 3 | SOCK_CLOEXEC, 0); TEMP_FAILURE_RETRY(socket(0, 3, 0)); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: 'socket' - // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, 3 | SOCK_CLOEXEC, 0)) + // CHECK-FIXES: TEMP_FAILURE_RETRY(socket(0, 3 | SOCK_CLOEXEC, 0)); int flag = 3; socket(0, flag, 0); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp index 3b977ad681adf..28b19ccdcf450 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp @@ -12,7 +12,7 @@ void g() { // CHECK-NOTES: [[@LINE+2]]:14: warning: argument name 'z' in comment does not match parameter name 'y' // CHECK-NOTES: [[@LINE-5]]:19: note: 'y' declared here f(/*y=*/0, /*z=*/0); - // CHECK-FIXES: {{^}} f(/*y=*/0, /*z=*/0); + // CHECK-FIXES: f(/*y=*/0, /*z=*/0); f(/*x=*/1, /*y=*/1); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inaccurate-erase.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inaccurate-erase.cpp index d29fa9cdd4e9b..dfb4b9e115fd5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/inaccurate-erase.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/inaccurate-erase.cpp @@ -51,12 +51,12 @@ struct custom_container { template void g() { T t; t.erase(std::remove(t.begin(), t.end(), 10)); - // CHECK-FIXES: {{^ }}t.erase(std::remove(t.begin(), t.end(), 10));{{$}} + // CHECK-FIXES: t.erase(std::remove(t.begin(), t.end(), 10)); std::vector v; v.erase(remove(v.begin(), v.end(), 10)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one - // CHECK-FIXES: {{^ }}v.erase(remove(v.begin(), v.end(), 10), v.end());{{$}} + // CHECK-FIXES: v.erase(remove(v.begin(), v.end(), 10), v.end()); } #define ERASE(x, y) x.erase(remove(x.begin(), x.end(), y)) @@ -67,34 +67,34 @@ int main() { v.erase(remove(v.begin(), v.end(), 10)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one item even when multiple items should be removed [bugprone-inaccurate-erase] - // CHECK-FIXES: {{^ }}v.erase(remove(v.begin(), v.end(), 10), v.end());{{$}} + // CHECK-FIXES: v.erase(remove(v.begin(), v.end(), 10), v.end()); v.erase(remove(v.begin(), v.end(), 20), v.end()); auto *p = &v; p->erase(remove(p->begin(), p->end(), 11)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one - // CHECK-FIXES: {{^ }}p->erase(remove(p->begin(), p->end(), 11), p->end());{{$}} + // CHECK-FIXES: p->erase(remove(p->begin(), p->end(), 11), p->end()); std::vector_with_const_iterator v2; v2.erase(remove(v2.begin(), v2.end(), 12)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one - // CHECK-FIXES: {{^ }}v2.erase(remove(v2.begin(), v2.end(), 12), v2.end());{{$}} + // CHECK-FIXES: v2.erase(remove(v2.begin(), v2.end(), 12), v2.end()); // Fix is not trivial. auto it = v.end(); v.erase(remove(v.begin(), it, 10)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this call will remove at most one - // CHECK-FIXES: {{^ }}v.erase(remove(v.begin(), it, 10));{{$}} + // CHECK-FIXES: v.erase(remove(v.begin(), it, 10)); g>(); g(); ERASE(v, 15); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: this call will remove at most one - // CHECK-FIXES: {{^ }}ERASE(v, 15);{{$}} + // CHECK-FIXES: ERASE(v, 15); std::vector> vupi; auto iter = vupi.begin(); vupi.erase(iter++); - // CHECK-FIXES: {{^ }}vupi.erase(iter++);{{$}} + // CHECK-FIXES: vupi.erase(iter++); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-shared-from-this.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-shared-from-this.cpp index 82b6ea84e6ff7..81d5cc52fb224 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-shared-from-this.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-shared-from-this.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11-or-later %s bugprone-incorrect-enable-shared-from-this %t +// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-incorrect-enable-shared-from-this %t // NOLINTBEGIN namespace std { @@ -8,15 +8,15 @@ namespace std { class BadClassExample : std::enable_shared_from_this {}; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'BadClassExample' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: public std::enable_shared_from_this +// CHECK-FIXES: class BadClassExample : public std::enable_shared_from_this {}; class BadClass2Example : private std::enable_shared_from_this {}; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'BadClass2Example' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: public std::enable_shared_from_this +// CHECK-FIXES: class BadClass2Example : public std::enable_shared_from_this {}; struct BadStructExample : private std::enable_shared_from_this {}; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'BadStructExample' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: public std::enable_shared_from_this +// CHECK-FIXES: struct BadStructExample : public std::enable_shared_from_this {}; class GoodClassExample : public std::enable_shared_from_this {}; @@ -29,15 +29,15 @@ class dummy_class2 {}; class BadMultiClassExample : std::enable_shared_from_this, dummy_class1 {}; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'BadMultiClassExample' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: public std::enable_shared_from_this, dummy_class1 +// CHECK-FIXES: class BadMultiClassExample : public std::enable_shared_from_this, dummy_class1 {}; class BadMultiClass2Example : dummy_class1, std::enable_shared_from_this, dummy_class2 {}; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'BadMultiClass2Example' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: dummy_class1, public std::enable_shared_from_this, dummy_class2 +// CHECK-FIXES: class BadMultiClass2Example : dummy_class1, public std::enable_shared_from_this, dummy_class2 {}; class BadMultiClass3Example : dummy_class1, dummy_class2, std::enable_shared_from_this {}; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'BadMultiClass3Example' is not publicly inheriting from 'std::enable_shared_from_this', which will cause unintended behaviour when using 'shared_from_this'; make the inheritance public [bugprone-incorrect-enable-shared-from-this] -// CHECK-FIXES: dummy_class1, dummy_class2, public std::enable_shared_from_this +// CHECK-FIXES: class BadMultiClass3Example : dummy_class1, dummy_class2, public std::enable_shared_from_this {}; class ClassBase : public std::enable_shared_from_this {}; class PrivateInheritClassBase : private ClassBase {}; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/misplaced-operator-in-strlen-in-alloc.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/misplaced-operator-in-strlen-in-alloc.cpp index 58d63fa7afd5e..bc7b47e38fa98 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/misplaced-operator-in-strlen-in-alloc.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/misplaced-operator-in-strlen-in-alloc.cpp @@ -17,7 +17,7 @@ size_t strlen(const char *); void bad_std_malloc_std_strlen(char *name) { char *new_name = (char *)std::malloc(std::strlen(name + 1)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: addition operator is applied to the argument of strlen - // CHECK-FIXES: {{^ char \*new_name = \(char \*\)std::malloc\(}}std::strlen(name) + 1{{\);$}} + // CHECK-FIXES: char *new_name = (char *)std::malloc(std::strlen(name) + 1); } void ignore_non_std_malloc_std_strlen(char *name) { @@ -35,7 +35,7 @@ void ignore_std_malloc_non_std_strlen(char *name) { void bad_new_strlen(char *name) { char *new_name = new char[std::strlen(name + 1)]; // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: addition operator is applied to the argument of strlen - // CHECK-FIXES: {{^ char \*new_name = new char\[}}std::strlen(name) + 1{{\];$}} + // CHECK-FIXES: char *new_name = new char[std::strlen(name) + 1]; } void good_new_strlen(char *name) { @@ -54,5 +54,5 @@ class C { void bad_custom_new_strlen(char *name) { C *new_name = new C[std::strlen(name + 1)]; // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: addition operator is applied to the argument of strlen - // CHECK-FIXES: {{^ C \*new_name = new C\[}}std::strlen(name) + 1{{\];$}} + // CHECK-FIXES: C *new_name = new C[std::strlen(name) + 1]; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp index 66cd6baa4382d..9f453678d1d19 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/move-forwarding-reference.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++14-or-later %s bugprone-move-forwarding-reference %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy -std=c++14-or-later %s bugprone-move-forwarding-reference %t -- -- -fno-delayed-template-parsing namespace std { template struct remove_reference; @@ -121,5 +121,5 @@ template void f11(U &&SomeU) { template void f12() { [] (auto&& x) { T SomeT(std::move(x)); }; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: forwarding reference passed to - // CHECK-FIXES: [] (auto&& x) { T SomeT(std::forward(x)); } + // CHECK-FIXES: [] (auto&& x) { T SomeT(std::forward(x)); }; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c index b241d683b0cdc..99d19ec953592 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-in-initialization-strlen.c @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \ +// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \ // RUN: -- -I %S/Inputs/not-null-terminated-result #include "not-null-terminated-result-c.h" @@ -40,7 +40,7 @@ int bad_strncmp_1(char *str1, const char *str2) { int length = strlen(str1) + 1; return strncmp(str1, str2, length); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str1, str2, length - 1); + // CHECK-FIXES: return strncmp(str1, str2, length - 1); } int good_strncmp_1(char *str1, const char *str2) { @@ -51,13 +51,13 @@ int good_strncmp_1(char *str1, const char *str2) { int bad_strncmp_2(char *str2) { return strncmp(str2, "foobar", (strlen("foobar") + 1)); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str2, "foobar", (strlen("foobar"))); + // CHECK-FIXES: return strncmp(str2, "foobar", (strlen("foobar"))); } int bad_strncmp_3(char *str3) { return strncmp(str3, "foobar", 1 + strlen("foobar")); // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str3, "foobar", strlen("foobar")); + // CHECK-FIXES: return strncmp(str3, "foobar", strlen("foobar")); } int good_strncmp_2_3(char *str) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe-cxx.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe-cxx.cpp index 8124b3bfa2268..8465b2bb81afd 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe-cxx.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-memcpy-safe-cxx.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \ +// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \ // RUN: -- -std=c++11 -I %S/Inputs/not-null-terminated-result #include "not-null-terminated-result-cxx.h" @@ -27,7 +27,7 @@ void bad_memcpy_known_dest(const char *src) { char dest01[13]; memcpy(dest01, src, strlen(src)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'memcpy' is not null-terminated [bugprone-not-null-terminated-result] - // CHECK-FIXES: dest01[14]; + // CHECK-FIXES: char dest01[14]; // CHECK-FIXES-NEXT: strcpy_s(dest01, src); } @@ -44,7 +44,7 @@ void bad_memcpy_full_source_length(std::string src) { char *dest20 = reinterpret_cast(malloc(src.size())); memcpy(dest20, src.data(), src.size()); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: the result from calling 'memcpy' is not null-terminated [bugprone-not-null-terminated-result] - // CHECK-FIXES: dest20 = reinterpret_cast(malloc(src.size() + 1)); + // CHECK-FIXES: char *dest20 = reinterpret_cast(malloc(src.size() + 1)); // CHECK-FIXES-NEXT: strcpy(dest20, src.data()); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c index 366c1698e4f2d..dccf4ed799499 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-strlen.c @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \ +// RUN: %check_clang_tidy %s bugprone-not-null-terminated-result %t -- \ // RUN: -- -I %S/Inputs/not-null-terminated-result // FIXME: Something wrong with the APInt un/signed conversion on Windows: @@ -70,13 +70,13 @@ void good_strerror_s(int errno) { int bad_strncmp_1(char *str0, const char *str1) { return strncmp(str0, str1, (strlen(str0) + 1)); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str0, str1, (strlen(str0))); + // CHECK-FIXES: return strncmp(str0, str1, (strlen(str0))); } int bad_strncmp_2(char *str2, const char *str3) { return strncmp(str2, str3, 1 + strlen(str2)); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str2, str3, strlen(str2)); + // CHECK-FIXES: return strncmp(str2, str3, strlen(str2)); } int good_strncmp_1_2(char *str4, const char *str5) { @@ -86,7 +86,7 @@ int good_strncmp_1_2(char *str4, const char *str5) { int bad_strncmp_3(char *str6) { return strncmp(str6, "string", 7); // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: strncmp(str6, "string", 6); + // CHECK-FIXES: return strncmp(str6, "string", 6); } int good_strncmp_3(char *str7) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp index 06e2db9d6e0d6..8047db3f19969 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/not-null-terminated-result-wcslen.cpp @@ -1,5 +1,5 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-not-null-terminated-result %t -- \ -// RUN: -- -std=c++11 -I %S/Inputs/not-null-terminated-result +// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-not-null-terminated-result %t -- \ +// RUN: -- -I %S/Inputs/not-null-terminated-result // FIXME: Something wrong with the APInt un/signed conversion on Windows: // in 'wcsncmp(wcs6, L"string", 7);' it tries to inject '4294967302' as length. @@ -58,13 +58,13 @@ void good_wmemmove_s_1(wchar_t *dest, const wchar_t *src) { int bad_wcsncmp_1(wchar_t *wcs0, const wchar_t *wcs1) { return wcsncmp(wcs0, wcs1, (wcslen(wcs0) + 1)); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: wcsncmp(wcs0, wcs1, (wcslen(wcs0))); + // CHECK-FIXES: return wcsncmp(wcs0, wcs1, (wcslen(wcs0))); } int bad_wcsncmp_2(wchar_t *wcs2, const wchar_t *wcs3) { return wcsncmp(wcs2, wcs3, 1 + wcslen(wcs2)); // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: wcsncmp(wcs2, wcs3, wcslen(wcs2)); + // CHECK-FIXES: return wcsncmp(wcs2, wcs3, wcslen(wcs2)); } int good_wcsncmp_1_2(wchar_t *wcs4, const wchar_t *wcs5) { @@ -74,7 +74,7 @@ int good_wcsncmp_1_2(wchar_t *wcs4, const wchar_t *wcs5) { int bad_wcsncmp_3(wchar_t *wcs6) { return wcsncmp(wcs6, L"string", 7); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: comparison length is too long and might lead to a buffer overflow [bugprone-not-null-terminated-result] - // CHECK-FIXES: wcsncmp(wcs6, L"string", 6); + // CHECK-FIXES: return wcsncmp(wcs6, L"string", 6); } int good_wcsncmp_3(wchar_t *wcs7) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp index 8db05362069f7..d0dfd978b7c37 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-posix-return %t +// RUN: %check_clang_tidy %s bugprone-posix-return %t #define NULL nullptr #define ZERO 0 @@ -43,40 +43,40 @@ extern "C" int pthread_yield(void); void warningLessThanZero() { if (posix_fadvise(0, 0, 0, 0) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: the comparison always evaluates to false because posix_fadvise always returns non-negative values - // CHECK-FIXES: posix_fadvise(0, 0, 0, 0) > 0 + // CHECK-FIXES: if (posix_fadvise(0, 0, 0, 0) > 0) {} if (posix_fallocate(0, 0, 0) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: - // CHECK-FIXES: posix_fallocate(0, 0, 0) > 0 + // CHECK-FIXES: if (posix_fallocate(0, 0, 0) > 0) {} if (posix_madvise(NULL, 0, 0) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: - // CHECK-FIXES: posix_madvise(NULL, 0, 0) > 0 + // CHECK-FIXES: if (posix_madvise(NULL, 0, 0) > 0) {} if (posix_memalign(NULL, 0, 0) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: - // CHECK-FIXES: posix_memalign(NULL, 0, 0) > 0 + // CHECK-FIXES: if (posix_memalign(NULL, 0, 0) > 0) {} if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:59: warning: - // CHECK-FIXES: posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0 + // CHECK-FIXES: if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0) {} if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:60: warning: - // CHECK-FIXES: posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0 + // CHECK-FIXES: if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) > 0) {} if (pthread_create(NULL, NULL, NULL, NULL) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: the comparison always evaluates to false because pthread_create always returns non-negative values - // CHECK-FIXES: pthread_create(NULL, NULL, NULL, NULL) > 0 + // CHECK-FIXES: if (pthread_create(NULL, NULL, NULL, NULL) > 0) {} if (pthread_attr_setaffinity_np(NULL, 0, NULL) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: - // CHECK-FIXES: pthread_attr_setaffinity_np(NULL, 0, NULL) > 0 + // CHECK-FIXES: if (pthread_attr_setaffinity_np(NULL, 0, NULL) > 0) {} if (pthread_attr_setschedpolicy(NULL, 0) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: - // CHECK-FIXES: pthread_attr_setschedpolicy(NULL, 0) > 0) + // CHECK-FIXES: if (pthread_attr_setschedpolicy(NULL, 0) > 0) {} if (pthread_attr_init(NULL) < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: - // CHECK-FIXES: pthread_attr_init(NULL) > 0 + // CHECK-FIXES: if (pthread_attr_init(NULL) > 0) {} if (pthread_yield() < 0) {} // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: - // CHECK-FIXES: pthread_yield() > 0 - if (0 > pthread_yield() ) {} + // CHECK-FIXES: if (pthread_yield() > 0) {} + if (0 > pthread_yield()) {} // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: - // CHECK-FIXES: 0 < pthread_yield() + // CHECK-FIXES: if (0 < pthread_yield()) {} } @@ -137,7 +137,7 @@ void warningEqualsNegative() { void WarningWithMacro() { if (posix_fadvise(0, 0, 0, 0) < ZERO) {} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: - // CHECK-FIXES: posix_fadvise(0, 0, 0, 0) > ZERO + // CHECK-FIXES: if (posix_fadvise(0, 0, 0, 0) > ZERO) {} if (posix_fadvise(0, 0, 0, 0) >= ZERO) {} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: if (posix_fadvise(0, 0, 0, 0) == NEGATIVE_ONE) {} @@ -150,7 +150,7 @@ void WarningWithMacro() { // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: if (pthread_create(NULL, NULL, NULL, NULL) < ZERO) {} // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: - // CHECK-FIXES: pthread_create(NULL, NULL, NULL, NULL) > ZERO + // CHECK-FIXES: if (pthread_create(NULL, NULL, NULL, NULL) > ZERO) {} if (pthread_create(NULL, NULL, NULL, NULL) >= ZERO) {} // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: if (pthread_create(NULL, NULL, NULL, NULL) == NEGATIVE_ONE) {} diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp index 62ad8de7d3007..0dbd7443f8edf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp @@ -12,16 +12,16 @@ void __f() {} void f(); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'f', which is not a reserved identifier [bugprone-reserved-identifier] -// CHECK-FIXES: {{^}}void __f();{{$}} +// CHECK-FIXES: void __f(); struct helper {}; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier 'helper', which is not a reserved identifier [bugprone-reserved-identifier] -// CHECK-FIXES: {{^}}struct __helper {};{{$}} +// CHECK-FIXES: struct __helper {}; struct Helper {}; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier 'Helper', which is not a reserved identifier [bugprone-reserved-identifier] -// CHECK-FIXES: {{^}}struct _Helper {};{{$}} +// CHECK-FIXES: struct _Helper {}; struct _helper2 {}; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier '_helper2', which is not a reserved identifier [bugprone-reserved-identifier] -// CHECK-FIXES: {{^}}struct __helper2 {};{{$}} +// CHECK-FIXES: struct __helper2 {}; template class reference_wrapper { @@ -53,11 +53,11 @@ ref(reference_wrapper<_Tp> __t) noexcept { template // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: declaration uses identifier 'Up', which is not a reserved identifier [bugprone-reserved-identifier] -// CHECK-FIXES: {{^}}template {{$}} +// CHECK-FIXES: template inline reference_wrapper cref(const Up &u) noexcept { // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: declaration uses identifier 'u', which is not a reserved identifier [bugprone-reserved-identifier] - // CHECK-FIXES: {{^}}cref(const _Up &__u) noexcept {{{$}} + // CHECK-FIXES: cref(const _Up &__u) noexcept { return reference_wrapper(u); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp index 8db47ea190d8f..e127788bf6ca6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp @@ -33,26 +33,26 @@ int main() { s = 6; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an integer is interpreted as a character code when assigning {{.*}} [bugprone-string-integer-assignment] -// CHECK-FIXES: {{^}} s = '6';{{$}} +// CHECK-FIXES: s = '6'; s = 66; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an integer is interpreted as a chara -// CHECK-FIXES: {{^}} s = "66";{{$}} +// CHECK-FIXES: s = "66"; s = x; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an integer is interpreted as a chara -// CHECK-FIXES: {{^}} s = std::to_string(x);{{$}} +// CHECK-FIXES: s = std::to_string(x); s = 'c'; s = static_cast(6); // += ws += 6; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an integer is interpreted as a chara -// CHECK-FIXES: {{^}} ws += L'6';{{$}} +// CHECK-FIXES: ws += L'6'; ws += 66; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an integer is interpreted as a chara -// CHECK-FIXES: {{^}} ws += L"66";{{$}} +// CHECK-FIXES: ws += L"66"; ws += x; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an integer is interpreted as a chara -// CHECK-FIXES: {{^}} ws += std::to_wstring(x);{{$}} +// CHECK-FIXES: ws += std::to_wstring(x); ws += L'c'; ws += (wchar_t)6; @@ -79,11 +79,11 @@ int main() { s += x % 26; s += 26 % x; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a chara - // CHECK-FIXES: {{^}} s += std::to_string(26 % x);{{$}} + // CHECK-FIXES: s += std::to_string(26 % x); s += c | 0x80; s += c | 0x8000; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a chara - // CHECK-FIXES: {{^}} s += std::to_string(c | 0x8000);{{$}} + // CHECK-FIXES: s += std::to_string(c | 0x8000); as += c | 0x8000; s += 'a' + (x % 26); @@ -94,7 +94,7 @@ int main() { s += x > 255 ? c : x; s += x > 255 ? 12 : x; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an integer is interpreted as a chara - // CHECK-FIXES: {{^}} s += std::to_string(x > 255 ? 12 : x);{{$}} + // CHECK-FIXES: s += std::to_string(x > 255 ? 12 : x); } namespace instantiation_dependent_exprs { @@ -104,7 +104,7 @@ struct S { std::string s; void f(char c) { s += c | static_cast(t); } // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an integer is interpreted as a chara - // CHECK-FIXES: {{^}} void f(char c) { s += std::to_string(c | static_cast(t)); } + // CHECK-FIXES: void f(char c) { s += std::to_string(c | static_cast(t)); } }; template struct S; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp index 129a841b88eaa..b85ba02e7e41b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/stringview-nullptr.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-stringview-nullptr -std=c++17 %t +// RUN: %check_clang_tidy %s bugprone-stringview-nullptr -std=c++17 %t namespace std { @@ -134,124 +134,128 @@ void temporary_construction() /* a */ { { (void)(std::string_view(nullptr)) /* a1 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing basic_string_view from null is undefined; replace with the default constructor - // CHECK-FIXES: {{^}} (void)(std::string_view()) /* a1 */; + // CHECK-FIXES: (void)(std::string_view()) /* a1 */; (void)(std::string_view((nullptr))) /* a2 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view()) /* a2 */; + // CHECK-FIXES: (void)(std::string_view()) /* a2 */; (void)(std::string_view({nullptr})) /* a3 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view()) /* a3 */; + // CHECK-FIXES: (void)(std::string_view()) /* a3 */; (void)(std::string_view({(nullptr)})) /* a4 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view()) /* a4 */; + // CHECK-FIXES: (void)(std::string_view()) /* a4 */; - (void)(std::string_view({})) /* a5 */; // Default `const CharT*` + // Default `const CharT*` + (void)(std::string_view({})) /* a5 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view()) /* a5 */; + // CHECK-FIXES: (void)(std::string_view()) /* a5 */; } // Temporary Object { (void)(std::string_view{nullptr}) /* a6 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view{}) /* a6 */; + // CHECK-FIXES: (void)(std::string_view{}) /* a6 */; (void)(std::string_view{(nullptr)}) /* a7 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view{}) /* a7 */; + // CHECK-FIXES: (void)(std::string_view{}) /* a7 */; (void)(std::string_view{{nullptr}}) /* a8 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view{}) /* a8 */; + // CHECK-FIXES: (void)(std::string_view{}) /* a8 */; (void)(std::string_view{{(nullptr)}}) /* a9 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view{}) /* a9 */; + // CHECK-FIXES: (void)(std::string_view{}) /* a9 */; - (void)(std::string_view{{}}) /* a10 */; // Default `const CharT*` + // Default `const CharT*` + (void)(std::string_view{{}}) /* a10 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(std::string_view{}) /* a10 */; + // CHECK-FIXES: (void)(std::string_view{}) /* a10 */; } // C-Style Cast && Compound Literal { (void)((std::string_view) nullptr) /* a11 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view) {}) /* a11 */; + // CHECK-FIXES: (void)((std::string_view) {}) /* a11 */; (void)((std::string_view)(nullptr)) /* a12 */; // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a12 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a12 */; (void)((std::string_view){nullptr}) /* a13 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a13 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a13 */; (void)((std::string_view){(nullptr)}) /* a14 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a14 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a14 */; (void)((std::string_view){{nullptr}}) /* a15 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a15 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a15 */; (void)((std::string_view){{(nullptr)}}) /* a16 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a16 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a16 */; - (void)((std::string_view){{}}) /* a17 */; // Default `const CharT*` + // Default `const CharT*` + (void)((std::string_view){{}}) /* a17 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((std::string_view){}) /* a17 */; + // CHECK-FIXES: (void)((std::string_view){}) /* a17 */; (void)((const std::string_view) nullptr) /* a18 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view) {}) /* a18 */; + // CHECK-FIXES: (void)((const std::string_view) {}) /* a18 */; (void)((const std::string_view)(nullptr)) /* a19 */; // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a19 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a19 */; (void)((const std::string_view){nullptr}) /* a20 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a20 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a20 */; (void)((const std::string_view){(nullptr)}) /* a21 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a21 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a21 */; (void)((const std::string_view){{nullptr}}) /* a22 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a22 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a22 */; (void)((const std::string_view){{(nullptr)}}) /* a23 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a23 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a23 */; - (void)((const std::string_view){{}}) /* a24 */; // Default `const CharT*` + // Default `const CharT*` + (void)((const std::string_view){{}}) /* a24 */; // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)((const std::string_view){}) /* a24 */; + // CHECK-FIXES: (void)((const std::string_view){}) /* a24 */; } // Static Cast { (void)(static_cast(nullptr)) /* a25 */; // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: casting to basic_string_view from null is undefined; replace with the empty string - // CHECK-FIXES: {{^}} (void)(static_cast("")) /* a25 */; + // CHECK-FIXES: (void)(static_cast("")) /* a25 */; (void)(static_cast((nullptr))) /* a26 */; // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(static_cast("")) /* a26 */; + // CHECK-FIXES: (void)(static_cast("")) /* a26 */; (void)(static_cast(nullptr)) /* a27 */; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(static_cast("")) /* a27 */; + // CHECK-FIXES: (void)(static_cast("")) /* a27 */; (void)(static_cast((nullptr))) /* a28 */; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(static_cast("")) /* a28 */; + // CHECK-FIXES: (void)(static_cast("")) /* a28 */; } } @@ -260,240 +264,246 @@ void stack_construction() /* b */ { { std::string_view b1 = nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b1 = {}; + // CHECK-FIXES: std::string_view b1 = {}; std::string_view b2 = (nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b2 = {}; + // CHECK-FIXES: std::string_view b2 = {}; const std::string_view b3 = nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b3 = {}; + // CHECK-FIXES: const std::string_view b3 = {}; const std::string_view b4 = (nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b4 = {}; + // CHECK-FIXES: const std::string_view b4 = {}; } // Copy Initialization With Temporary { std::string_view b5 = std::string_view(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b5 = std::string_view(); + // CHECK-FIXES: std::string_view b5 = std::string_view(); std::string_view b6 = std::string_view{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b6 = std::string_view{}; + // CHECK-FIXES: std::string_view b6 = std::string_view{}; std::string_view b7 = (std::string_view) nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b7 = (std::string_view) {}; + // CHECK-FIXES: std::string_view b7 = (std::string_view) {}; std::string_view b8 = (std::string_view){nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b8 = (std::string_view){}; + // CHECK-FIXES: std::string_view b8 = (std::string_view){}; std::string_view b9 = static_cast(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view b9 = static_cast(""); + // CHECK-FIXES: std::string_view b9 = static_cast(""); } // Copy List Initialization { std::string_view b10 = {nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b10 = {}; + // CHECK-FIXES: std::string_view b10 = {}; std::string_view b11 = {(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b11 = {}; + // CHECK-FIXES: std::string_view b11 = {}; std::string_view b12 = {{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b12 = {}; + // CHECK-FIXES: std::string_view b12 = {}; std::string_view b13 = {{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b13 = {}; + // CHECK-FIXES: std::string_view b13 = {}; - std::string_view b14 = {{}}; // Default `const CharT*` + // Default `const CharT*` + std::string_view b14 = {{}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b14 = {}; + // CHECK-FIXES: std::string_view b14 = {}; const std::string_view b15 = {nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b15 = {}; + // CHECK-FIXES: const std::string_view b15 = {}; const std::string_view b16 = {(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b16 = {}; + // CHECK-FIXES: const std::string_view b16 = {}; const std::string_view b17 = {{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b17 = {}; + // CHECK-FIXES: const std::string_view b17 = {}; const std::string_view b18 = {{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b18 = {}; + // CHECK-FIXES: const std::string_view b18 = {}; - const std::string_view b19 = {{}}; // Default `const CharT*` + // Default `const CharT*` + const std::string_view b19 = {{}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b19 = {}; + // CHECK-FIXES: const std::string_view b19 = {}; } // Copy List Initialization With Temporary { std::string_view b20 = {std::string_view(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b20 = {std::string_view()}; + // CHECK-FIXES: std::string_view b20 = {std::string_view()}; std::string_view b21 = {std::string_view{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b21 = {std::string_view{}}; + // CHECK-FIXES: std::string_view b21 = {std::string_view{}}; std::string_view b22 = {(std::string_view) nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b22 = {(std::string_view) {}}; + // CHECK-FIXES: std::string_view b22 = {(std::string_view) {}}; std::string_view b23 = {(std::string_view){nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b23 = {(std::string_view){}}; + // CHECK-FIXES: std::string_view b23 = {(std::string_view){}}; std::string_view b24 = {static_cast(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view b24 = {static_cast("")}; + // CHECK-FIXES: std::string_view b24 = {static_cast("")}; } // Direct Initialization { std::string_view b25(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b25; + // CHECK-FIXES: std::string_view b25; std::string_view b26((nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b26; + // CHECK-FIXES: std::string_view b26; std::string_view b27({nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b27; + // CHECK-FIXES: std::string_view b27; std::string_view b28({(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b28; + // CHECK-FIXES: std::string_view b28; - std::string_view b29({}); // Default `const CharT*` + // Default `const CharT*` + std::string_view b29({}); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b29; + // CHECK-FIXES: std::string_view b29; const std::string_view b30(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b30; + // CHECK-FIXES: const std::string_view b30; const std::string_view b31((nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b31; + // CHECK-FIXES: const std::string_view b31; const std::string_view b32({nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b32; + // CHECK-FIXES: const std::string_view b32; const std::string_view b33({(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b33; + // CHECK-FIXES: const std::string_view b33; - const std::string_view b34({}); // Default `const CharT*` + // Default `const CharT*` + const std::string_view b34({}); // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b34; + // CHECK-FIXES: const std::string_view b34; } // Direct Initialization With Temporary { std::string_view b35(std::string_view(nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b35(std::string_view()); + // CHECK-FIXES: std::string_view b35(std::string_view()); std::string_view b36(std::string_view{nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b36(std::string_view{}); + // CHECK-FIXES: std::string_view b36(std::string_view{}); std::string_view b37((std::string_view) nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b37((std::string_view) {}); + // CHECK-FIXES: std::string_view b37((std::string_view) {}); std::string_view b38((std::string_view){nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b38((std::string_view){}); + // CHECK-FIXES: std::string_view b38((std::string_view){}); std::string_view b39(static_cast(nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view b39(static_cast("")); + // CHECK-FIXES: std::string_view b39(static_cast("")); } // Direct List Initialization { std::string_view b40{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b40{}; + // CHECK-FIXES: std::string_view b40{}; std::string_view b41{(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b41{}; + // CHECK-FIXES: std::string_view b41{}; std::string_view b42{{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b42{}; + // CHECK-FIXES: std::string_view b42{}; std::string_view b43{{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b43{}; + // CHECK-FIXES: std::string_view b43{}; - std::string_view b44{{}}; // Default `const CharT*` + // Default `const CharT*` + std::string_view b44{{}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b44{}; + // CHECK-FIXES: std::string_view b44{}; const std::string_view b45{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b45{}; + // CHECK-FIXES: const std::string_view b45{}; const std::string_view b46{(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b46{}; + // CHECK-FIXES: const std::string_view b46{}; const std::string_view b47{{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b47{}; + // CHECK-FIXES: const std::string_view b47{}; const std::string_view b48{{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b48{}; + // CHECK-FIXES: const std::string_view b48{}; - const std::string_view b49{{}}; // Default `const CharT*` + // Default `const CharT*` + const std::string_view b49{{}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view b49{}; + // CHECK-FIXES: const std::string_view b49{}; } // Direct List Initialization With Temporary { std::string_view b50{std::string_view(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b50{std::string_view()}; + // CHECK-FIXES: std::string_view b50{std::string_view()}; std::string_view b51{std::string_view{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b51{std::string_view{}}; + // CHECK-FIXES: std::string_view b51{std::string_view{}}; std::string_view b52{(std::string_view) nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b52{(std::string_view) {}}; + // CHECK-FIXES: std::string_view b52{(std::string_view) {}}; std::string_view b53{(std::string_view){nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view b53{(std::string_view){}}; + // CHECK-FIXES: std::string_view b53{(std::string_view){}}; std::string_view b54{static_cast(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view b54{static_cast("")}; + // CHECK-FIXES: std::string_view b54{static_cast("")}; } } @@ -503,169 +513,173 @@ void field_construction() /* c */ { struct DMICopyInitialization { std::string_view c1 = nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c1 = {}; + // CHECK-FIXES: std::string_view c1 = {}; std::string_view c2 = (nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c2 = {}; + // CHECK-FIXES: std::string_view c2 = {}; const std::string_view c3 = nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c3 = {}; + // CHECK-FIXES: const std::string_view c3 = {}; const std::string_view c4 = (nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c4 = {}; + // CHECK-FIXES: const std::string_view c4 = {}; }; struct DMICopyInitializationWithTemporary { std::string_view c5 = std::string_view(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c5 = std::string_view(); + // CHECK-FIXES: std::string_view c5 = std::string_view(); std::string_view c6 = std::string_view{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c6 = std::string_view{}; + // CHECK-FIXES: std::string_view c6 = std::string_view{}; std::string_view c7 = (std::string_view) nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c7 = (std::string_view) {}; + // CHECK-FIXES: std::string_view c7 = (std::string_view) {}; std::string_view c8 = (std::string_view){nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c8 = (std::string_view){}; + // CHECK-FIXES: std::string_view c8 = (std::string_view){}; std::string_view c9 = static_cast(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view c9 = static_cast(""); + // CHECK-FIXES: std::string_view c9 = static_cast(""); }; struct DMICopyListInitialization { std::string_view c10 = {nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c10 = {}; + // CHECK-FIXES: std::string_view c10 = {}; std::string_view c11 = {(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c11 = {}; + // CHECK-FIXES: std::string_view c11 = {}; std::string_view c12 = {{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c12 = {}; + // CHECK-FIXES: std::string_view c12 = {}; std::string_view c13 = {{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c13 = {}; + // CHECK-FIXES: std::string_view c13 = {}; - std::string_view c14 = {{}}; // Default `const CharT*` + // Default `const CharT*` + std::string_view c14 = {{}}; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c14 = {}; + // CHECK-FIXES: std::string_view c14 = {}; const std::string_view c15 = {nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c15 = {}; + // CHECK-FIXES: const std::string_view c15 = {}; const std::string_view c16 = {(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c16 = {}; + // CHECK-FIXES: const std::string_view c16 = {}; const std::string_view c17 = {{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c17 = {}; + // CHECK-FIXES: const std::string_view c17 = {}; const std::string_view c18 = {{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c18 = {}; + // CHECK-FIXES: const std::string_view c18 = {}; - const std::string_view c19 = {{}}; // Default `const CharT*` + // Default `const CharT*` + const std::string_view c19 = {{}}; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c19 = {}; + // CHECK-FIXES: const std::string_view c19 = {}; }; struct DMICopyListInitializationWithTemporary { std::string_view c20 = {std::string_view(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c20 = {std::string_view()}; + // CHECK-FIXES: std::string_view c20 = {std::string_view()}; std::string_view c21 = {std::string_view{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c21 = {std::string_view{}}; + // CHECK-FIXES: std::string_view c21 = {std::string_view{}}; std::string_view c22 = {(std::string_view) nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c22 = {(std::string_view) {}}; + // CHECK-FIXES: std::string_view c22 = {(std::string_view) {}}; std::string_view c23 = {(std::string_view){nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c23 = {(std::string_view){}}; + // CHECK-FIXES: std::string_view c23 = {(std::string_view){}}; std::string_view c24 = {static_cast(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view c24 = {static_cast("")}; + // CHECK-FIXES: std::string_view c24 = {static_cast("")}; }; struct DMIDirectListInitialization { std::string_view c25{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c25{}; + // CHECK-FIXES: std::string_view c25{}; std::string_view c26{(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c26{}; + // CHECK-FIXES: std::string_view c26{}; std::string_view c27{{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c27{}; + // CHECK-FIXES: std::string_view c27{}; std::string_view c28{{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c28{}; + // CHECK-FIXES: std::string_view c28{}; - std::string_view c29{{}}; // Default `const CharT*` + // Default `const CharT*` + std::string_view c29{{}}; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c29{}; + // CHECK-FIXES: std::string_view c29{}; const std::string_view c30{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c30{}; + // CHECK-FIXES: const std::string_view c30{}; const std::string_view c31{(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c31{}; + // CHECK-FIXES: const std::string_view c31{}; const std::string_view c32{{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c32{}; + // CHECK-FIXES: const std::string_view c32{}; const std::string_view c33{{(nullptr)}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c33{}; + // CHECK-FIXES: const std::string_view c33{}; - const std::string_view c34{{}}; // Default `const CharT*` + // Default `const CharT*` + const std::string_view c34{{}}; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} const std::string_view c34{}; + // CHECK-FIXES: const std::string_view c34{}; }; struct DMIDirectListInitializationWithTemporary { std::string_view c35{std::string_view(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c35{std::string_view()}; + // CHECK-FIXES: std::string_view c35{std::string_view()}; std::string_view c36{std::string_view{nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c36{std::string_view{}}; + // CHECK-FIXES: std::string_view c36{std::string_view{}}; std::string_view c37{(std::string_view) nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c37{(std::string_view) {}}; + // CHECK-FIXES: std::string_view c37{(std::string_view) {}}; std::string_view c38{(std::string_view){nullptr}}; // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} std::string_view c38{(std::string_view){}}; + // CHECK-FIXES: std::string_view c38{(std::string_view){}}; std::string_view c39{static_cast(nullptr)}; // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} std::string_view c39{static_cast("")}; + // CHECK-FIXES: std::string_view c39{static_cast("")}; }; // Constructor Initializers @@ -680,23 +694,24 @@ void field_construction() /* c */ { CIDirectInitialization() : c40(nullptr), // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} : c40(), + // CHECK-FIXES: : c40(), c41((nullptr)), // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c41(), + // CHECK-FIXES: c41(), c42({nullptr}), // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c42(), + // CHECK-FIXES: c42(), c43({(nullptr)}), // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c43(), + // CHECK-FIXES: c43(), - c44({}) { // Default `const CharT*` + // Default `const CharT*` + c44({}) { // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c44() { + // CHECK-FIXES: c44() { } }; @@ -710,23 +725,23 @@ void field_construction() /* c */ { CIDirectInitializationWithTemporary() : c45(std::string_view(nullptr)), // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} : c45(std::string_view()), + // CHECK-FIXES: : c45(std::string_view()), c46(std::string_view{nullptr}), // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c46(std::string_view{}), + // CHECK-FIXES: c46(std::string_view{}), c47((std::string_view) nullptr), // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c47((std::string_view) {}), + // CHECK-FIXES: c47((std::string_view) {}), c48((std::string_view){nullptr}), // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c48((std::string_view){}), + // CHECK-FIXES: c48((std::string_view){}), c49(static_cast(nullptr)) { // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} c49(static_cast("")) { + // CHECK-FIXES: c49(static_cast("")) { } }; @@ -740,23 +755,24 @@ void field_construction() /* c */ { CIDirectListInitialization() : c50{nullptr}, // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} : c50{}, + // CHECK-FIXES: : c50{}, c51{(nullptr)}, // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c51{}, + // CHECK-FIXES: c51{}, c52{{nullptr}}, // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c52{}, + // CHECK-FIXES: c52{}, c53{{(nullptr)}}, // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c53{}, + // CHECK-FIXES: c53{}, - c54{{}} { // Default `const CharT*` + // Default `const CharT*` + c54{{}} { // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c54{} { + // CHECK-FIXES: c54{} { } }; @@ -770,23 +786,23 @@ void field_construction() /* c */ { CIDirectListInitializationWithTemporary() : c55{std::string_view(nullptr)}, // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} : c55{std::string_view()}, + // CHECK-FIXES: : c55{std::string_view()}, c56{std::string_view{nullptr}}, // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c56{std::string_view{}}, + // CHECK-FIXES: c56{std::string_view{}}, c57{(std::string_view) nullptr}, // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c57{(std::string_view) {}}, + // CHECK-FIXES: c57{(std::string_view) {}}, c58{(std::string_view){nullptr}}, // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} c58{(std::string_view){}}, + // CHECK-FIXES: c58{(std::string_view){}}, c59{static_cast(nullptr)} { // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} c59{static_cast("")} { + // CHECK-FIXES: c59{static_cast("")} { } }; } @@ -796,108 +812,110 @@ void default_argument_construction() /* d */ { { void d1(std::string_view sv = nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d1(std::string_view sv = {}); + // CHECK-FIXES: void d1(std::string_view sv = {}); void d2(std::string_view sv = (nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d2(std::string_view sv = {}); + // CHECK-FIXES: void d2(std::string_view sv = {}); void d3(const std::string_view sv = nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d3(const std::string_view sv = {}); + // CHECK-FIXES: void d3(const std::string_view sv = {}); void d4(const std::string_view sv = (nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d4(const std::string_view sv = {}); + // CHECK-FIXES: void d4(const std::string_view sv = {}); } // Copy Initialization With Temporary { void d5(std::string_view sv = std::string_view(nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d5(std::string_view sv = std::string_view()); + // CHECK-FIXES: void d5(std::string_view sv = std::string_view()); void d6(std::string_view sv = std::string_view{nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d6(std::string_view sv = std::string_view{}); + // CHECK-FIXES: void d6(std::string_view sv = std::string_view{}); void d7(std::string_view sv = (std::string_view) nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d7(std::string_view sv = (std::string_view) {}); + // CHECK-FIXES: void d7(std::string_view sv = (std::string_view) {}); void d8(std::string_view sv = (std::string_view){nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d8(std::string_view sv = (std::string_view){}); + // CHECK-FIXES: void d8(std::string_view sv = (std::string_view){}); void d9(std::string_view sv = static_cast(nullptr)); // CHECK-MESSAGES: :[[@LINE-1]]:51: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} void d9(std::string_view sv = static_cast("")); + // CHECK-FIXES: void d9(std::string_view sv = static_cast("")); } // Copy List Initialization { void d10(std::string_view sv = {nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d10(std::string_view sv = {}); + // CHECK-FIXES: void d10(std::string_view sv = {}); void d11(std::string_view sv = {(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d11(std::string_view sv = {}); + // CHECK-FIXES: void d11(std::string_view sv = {}); void d12(std::string_view sv = {{nullptr}}); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d12(std::string_view sv = {}); + // CHECK-FIXES: void d12(std::string_view sv = {}); void d13(std::string_view sv = {{(nullptr)}}); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d13(std::string_view sv = {}); + // CHECK-FIXES: void d13(std::string_view sv = {}); - void d14(std::string_view sv = {{}}); // Default `const CharT*` + // Default `const CharT*` + void d14(std::string_view sv = {{}}); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d14(std::string_view sv = {}); + // CHECK-FIXES: void d14(std::string_view sv = {}); void d15(const std::string_view sv = {nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d15(const std::string_view sv = {}); + // CHECK-FIXES: void d15(const std::string_view sv = {}); void d16(const std::string_view sv = {(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d16(const std::string_view sv = {}); + // CHECK-FIXES: void d16(const std::string_view sv = {}); void d17(const std::string_view sv = {{nullptr}}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d17(const std::string_view sv = {}); + // CHECK-FIXES: void d17(const std::string_view sv = {}); void d18(const std::string_view sv = {{(nullptr)}}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d18(const std::string_view sv = {}); + // CHECK-FIXES: void d18(const std::string_view sv = {}); - void d19(const std::string_view sv = {{}}); // Default `const CharT*` + // Default `const CharT*` + void d19(const std::string_view sv = {{}}); // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d19(const std::string_view sv = {}); + // CHECK-FIXES: void d19(const std::string_view sv = {}); } // Copy List Initialization With Temporary { void d20(std::string_view sv = {std::string_view(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d20(std::string_view sv = {std::string_view()}); + // CHECK-FIXES: void d20(std::string_view sv = {std::string_view()}); void d21(std::string_view sv = {std::string_view{nullptr}}); // CHECK-MESSAGES: :[[@LINE-1]]:54: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d21(std::string_view sv = {std::string_view{}}); + // CHECK-FIXES: void d21(std::string_view sv = {std::string_view{}}); void d22(std::string_view sv = {(std::string_view) nullptr}); // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d22(std::string_view sv = {(std::string_view) {}}); + // CHECK-FIXES: void d22(std::string_view sv = {(std::string_view) {}}); void d23(std::string_view sv = {(std::string_view){nullptr}}); // CHECK-MESSAGES: :[[@LINE-1]]:56: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} void d23(std::string_view sv = {(std::string_view){}}); + // CHECK-FIXES: void d23(std::string_view sv = {(std::string_view){}}); void d24(std::string_view sv = {static_cast(nullptr)}); // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} void d24(std::string_view sv = {static_cast("")}); + // CHECK-FIXES: void d24(std::string_view sv = {static_cast("")}); } } @@ -906,132 +924,136 @@ void heap_construction() /* e */ { { (void)(new std::string_view(nullptr)) /* e1 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view()) /* e1 */; + // CHECK-FIXES: (void)(new std::string_view()) /* e1 */; (void)(new std::string_view((nullptr))) /* e2 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view()) /* e2 */; + // CHECK-FIXES: (void)(new std::string_view()) /* e2 */; (void)(new std::string_view({nullptr})) /* e3 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view()) /* e3 */; + // CHECK-FIXES: (void)(new std::string_view()) /* e3 */; (void)(new std::string_view({(nullptr)})) /* e4 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view()) /* e4 */; + // CHECK-FIXES: (void)(new std::string_view()) /* e4 */; - (void)(new std::string_view({})) /* e5 */; // Default `const CharT*` + // Default `const CharT*` + (void)(new std::string_view({})) /* e5 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view()) /* e5 */; + // CHECK-FIXES: (void)(new std::string_view()) /* e5 */; (void)(new const std::string_view(nullptr)) /* e6 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view()) /* e6 */; + // CHECK-FIXES: (void)(new const std::string_view()) /* e6 */; (void)(new const std::string_view((nullptr))) /* e7 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view()) /* e7 */; + // CHECK-FIXES: (void)(new const std::string_view()) /* e7 */; (void)(new const std::string_view({nullptr})) /* e8 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view()) /* e8 */; + // CHECK-FIXES: (void)(new const std::string_view()) /* e8 */; (void)(new const std::string_view({(nullptr)})) /* e9 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view()) /* e9 */; + // CHECK-FIXES: (void)(new const std::string_view()) /* e9 */; - (void)(new const std::string_view({})) /* e10 */; // Default `const CharT*` + // Default `const CharT*` + (void)(new const std::string_view({})) /* e10 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view()) /* e10 */; + // CHECK-FIXES: (void)(new const std::string_view()) /* e10 */; } // Direct Initialization With Temporary { (void)(new std::string_view(std::string_view(nullptr))) /* e11 */; // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view(std::string_view())) /* e11 */; + // CHECK-FIXES: (void)(new std::string_view(std::string_view())) /* e11 */; (void)(new std::string_view(std::string_view{nullptr})) /* e12 */; // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view(std::string_view{})) /* e12 */; + // CHECK-FIXES: (void)(new std::string_view(std::string_view{})) /* e12 */; (void)(new std::string_view((std::string_view) nullptr)) /* e13 */; // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view((std::string_view) {})) /* e13 */; + // CHECK-FIXES: (void)(new std::string_view((std::string_view) {})) /* e13 */; (void)(new std::string_view((std::string_view){nullptr})) /* e14 */; // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view((std::string_view){})) /* e14 */; + // CHECK-FIXES: (void)(new std::string_view((std::string_view){})) /* e14 */; (void)(new std::string_view(static_cast(nullptr))) /* e15 */; // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(new std::string_view(static_cast(""))) /* e15 */; + // CHECK-FIXES: (void)(new std::string_view(static_cast(""))) /* e15 */; } // Direct List Initialization { (void)(new std::string_view{nullptr}) /* e16 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{}) /* e16 */; + // CHECK-FIXES: (void)(new std::string_view{}) /* e16 */; (void)(new std::string_view{(nullptr)}) /* e17 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{}) /* e17 */; + // CHECK-FIXES: (void)(new std::string_view{}) /* e17 */; (void)(new std::string_view{{nullptr}}) /* e18 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{}) /* e18 */; + // CHECK-FIXES: (void)(new std::string_view{}) /* e18 */; (void)(new std::string_view{{(nullptr)}}) /* e19 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{}) /* e19 */; + // CHECK-FIXES: (void)(new std::string_view{}) /* e19 */; - (void)(new std::string_view{{}}) /* e20 */; // Default `const CharT*` + // Default `const CharT*` + (void)(new std::string_view{{}}) /* e20 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{}) /* e20 */; + // CHECK-FIXES: (void)(new std::string_view{}) /* e20 */; (void)(new const std::string_view{nullptr}) /* e21 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view{}) /* e21 */; + // CHECK-FIXES: (void)(new const std::string_view{}) /* e21 */; (void)(new const std::string_view{(nullptr)}) /* e22 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view{}) /* e22 */; + // CHECK-FIXES: (void)(new const std::string_view{}) /* e22 */; (void)(new const std::string_view{{nullptr}}) /* e23 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view{}) /* e23 */; + // CHECK-FIXES: (void)(new const std::string_view{}) /* e23 */; (void)(new const std::string_view{{(nullptr)}}) /* e24 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view{}) /* e24 */; + // CHECK-FIXES: (void)(new const std::string_view{}) /* e24 */; - (void)(new const std::string_view{{}}) /* e25 */; // Default `const CharT*` + // Default `const CharT*` + (void)(new const std::string_view{{}}) /* e25 */; // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new const std::string_view{}) /* e25 */; + // CHECK-FIXES: (void)(new const std::string_view{}) /* e25 */; } // Direct List Initialization With Temporary { (void)(new std::string_view{std::string_view(nullptr)}) /* e26 */; // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{std::string_view()}) /* e26 */; + // CHECK-FIXES: (void)(new std::string_view{std::string_view()}) /* e26 */; (void)(new std::string_view{std::string_view{nullptr}}) /* e27 */; // CHECK-MESSAGES: :[[@LINE-1]]:50: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{std::string_view{}}) /* e27 */; + // CHECK-FIXES: (void)(new std::string_view{std::string_view{}}) /* e27 */; (void)(new std::string_view{(std::string_view) nullptr}) /* e28 */; // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{(std::string_view) {}}) /* e28 */; + // CHECK-FIXES: (void)(new std::string_view{(std::string_view) {}}) /* e28 */; (void)(new std::string_view{(std::string_view){nullptr}}) /* e29 */; // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(new std::string_view{(std::string_view){}}) /* e29 */; + // CHECK-FIXES: (void)(new std::string_view{(std::string_view){}}) /* e29 */; (void)(new std::string_view{static_cast(nullptr)}) /* e30 */; // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(new std::string_view{static_cast("")}) /* e30 */; + // CHECK-FIXES: (void)(new std::string_view{static_cast("")}) /* e30 */; } } @@ -1040,46 +1062,47 @@ void function_argument_initialization() /* f */ { { function(nullptr) /* f1 */; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing null as basic_string_view is undefined; replace with the empty string - // CHECK-FIXES: {{^}} function("") /* f1 */; + // CHECK-FIXES: function("") /* f1 */; function((nullptr)) /* f2 */; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} function("") /* f2 */; + // CHECK-FIXES: function("") /* f2 */; function({nullptr}) /* f3 */; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} function("") /* f3 */; + // CHECK-FIXES: function("") /* f3 */; function({(nullptr)}) /* f4 */; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} function("") /* f4 */; + // CHECK-FIXES: function("") /* f4 */; - function({{}}) /* f5 */; // Default `const CharT*` + // Default `const CharT*` + function({{}}) /* f5 */; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} function("") /* f5 */; + // CHECK-FIXES: function("") /* f5 */; } // Function Argument Initialization With Temporary { function(std::string_view(nullptr)) /* f6 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} function(std::string_view()) /* f6 */; + // CHECK-FIXES: function(std::string_view()) /* f6 */; function(std::string_view{nullptr}) /* f7 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} function(std::string_view{}) /* f7 */; + // CHECK-FIXES: function(std::string_view{}) /* f7 */; function((std::string_view) nullptr) /* f8 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} function((std::string_view) {}) /* f8 */; + // CHECK-FIXES: function((std::string_view) {}) /* f8 */; function((std::string_view){nullptr}) /* f9 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} function((std::string_view){}) /* f9 */; + // CHECK-FIXES: function((std::string_view){}) /* f9 */; function(static_cast(nullptr)) /* f10 */; // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} function(static_cast("")) /* f10 */; + // CHECK-FIXES: function(static_cast("")) /* f10 */; } } @@ -1088,46 +1111,47 @@ void assignment(std::string_view sv) /* g */ { { sv = nullptr /* g1 */; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment to basic_string_view from null is undefined; replace with the default constructor - // CHECK-FIXES: {{^}} sv = {} /* g1 */; + // CHECK-FIXES: sv = {} /* g1 */; sv = (nullptr) /* g2 */; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} sv = {} /* g2 */; + // CHECK-FIXES: sv = {} /* g2 */; sv = {nullptr} /* g3 */; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} sv = {} /* g3 */; + // CHECK-FIXES: sv = {} /* g3 */; sv = {(nullptr)} /* g4 */; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} sv = {} /* g4 */; + // CHECK-FIXES: sv = {} /* g4 */; - sv = {{}} /* g5 */; // Default `const CharT*` + // Default `const CharT*` + sv = {{}} /* g5 */; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} sv = {} /* g5 */; + // CHECK-FIXES: sv = {} /* g5 */; } // Assignment With Temporary { sv = std::string_view(nullptr) /* g6 */; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} sv = std::string_view() /* g6 */; + // CHECK-FIXES: sv = std::string_view() /* g6 */; sv = std::string_view{nullptr} /* g7 */; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} sv = std::string_view{} /* g7 */; + // CHECK-FIXES: sv = std::string_view{} /* g7 */; sv = (std::string_view) nullptr /* g8 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} sv = (std::string_view) {} /* g8 */; + // CHECK-FIXES: sv = (std::string_view) {} /* g8 */; sv = (std::string_view){nullptr} /* g9 */; // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} sv = (std::string_view){} /* g9 */; + // CHECK-FIXES: sv = (std::string_view){} /* g9 */; sv = static_cast(nullptr) /* g10 */; // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} sv = static_cast("") /* g10 */; + // CHECK-FIXES: sv = static_cast("") /* g10 */; } } @@ -1136,46 +1160,47 @@ void pointer_assignment(std::string_view *sv_ptr) /* h */ { { *sv_ptr = nullptr /* h1 */; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = {} /* h1 */; + // CHECK-FIXES: *sv_ptr = {} /* h1 */; *sv_ptr = (nullptr) /* h2 */; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = {} /* h2 */; + // CHECK-FIXES: *sv_ptr = {} /* h2 */; *sv_ptr = {nullptr} /* h3 */; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = {} /* h3 */; + // CHECK-FIXES: *sv_ptr = {} /* h3 */; *sv_ptr = {(nullptr)} /* h4 */; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = {} /* h4 */; + // CHECK-FIXES: *sv_ptr = {} /* h4 */; - *sv_ptr = {{}} /* h5 */; // Default `const CharT*` + // Default `const CharT*` + *sv_ptr = {{}} /* h5 */; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: assignment{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = {} /* h5 */; + // CHECK-FIXES: *sv_ptr = {} /* h5 */; } // Assignment With Temporary { *sv_ptr = std::string_view(nullptr) /* h6 */; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = std::string_view() /* h6 */; + // CHECK-FIXES: *sv_ptr = std::string_view() /* h6 */; *sv_ptr = std::string_view{nullptr} /* h7 */; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = std::string_view{} /* h7 */; + // CHECK-FIXES: *sv_ptr = std::string_view{} /* h7 */; *sv_ptr = (std::string_view) nullptr /* h8 */; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = (std::string_view) {} /* h8 */; + // CHECK-FIXES: *sv_ptr = (std::string_view) {} /* h8 */; *sv_ptr = (std::string_view){nullptr} /* h9 */; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} *sv_ptr = (std::string_view){} /* h9 */; + // CHECK-FIXES: *sv_ptr = (std::string_view){} /* h9 */; *sv_ptr = static_cast(nullptr) /* h10 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} *sv_ptr = static_cast("") /* h10 */; + // CHECK-FIXES: *sv_ptr = static_cast("") /* h10 */; } } @@ -1184,38 +1209,38 @@ void lesser_comparison(std::string_view sv) /* i */ { { (void)(sv < nullptr) /* i1 */; // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: comparing basic_string_view to null is undefined; replace with the empty string - // CHECK-FIXES: {{^}} (void)(sv < "") /* i1 */; + // CHECK-FIXES: (void)(sv < "") /* i1 */; (void)(sv < (nullptr)) /* i2 */; // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv < "") /* i2 */; + // CHECK-FIXES: (void)(sv < "") /* i2 */; (void)(nullptr < sv) /* i3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" < sv) /* i3 */; + // CHECK-FIXES: (void)("" < sv) /* i3 */; (void)((nullptr) < sv) /* i4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" < sv) /* i4 */; + // CHECK-FIXES: (void)("" < sv) /* i4 */; } // With Equality { (void)(sv <= nullptr) /* i5 */; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv <= "") /* i5 */; + // CHECK-FIXES: (void)(sv <= "") /* i5 */; (void)(sv <= (nullptr)) /* i6 */; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv <= "") /* i6 */; + // CHECK-FIXES: (void)(sv <= "") /* i6 */; (void)(nullptr <= sv) /* i7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" <= sv) /* i7 */; + // CHECK-FIXES: (void)("" <= sv) /* i7 */; (void)((nullptr) <= sv) /* i8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" <= sv) /* i8 */; + // CHECK-FIXES: (void)("" <= sv) /* i8 */; } } @@ -1224,38 +1249,38 @@ void pointer_lesser_comparison(std::string_view *sv_ptr) /* j */ { { (void)(*sv_ptr < nullptr) /* j1 */; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr < "") /* j1 */; + // CHECK-FIXES: (void)(*sv_ptr < "") /* j1 */; (void)(*sv_ptr < (nullptr)) /* j2 */; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr < "") /* j2 */; + // CHECK-FIXES: (void)(*sv_ptr < "") /* j2 */; (void)(nullptr < *sv_ptr) /* j3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" < *sv_ptr) /* j3 */; + // CHECK-FIXES: (void)("" < *sv_ptr) /* j3 */; (void)((nullptr) < *sv_ptr) /* j4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" < *sv_ptr) /* j4 */; + // CHECK-FIXES: (void)("" < *sv_ptr) /* j4 */; } // With Equality { (void)(*sv_ptr <= nullptr) /* j5 */; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr <= "") /* j5 */; + // CHECK-FIXES: (void)(*sv_ptr <= "") /* j5 */; (void)(*sv_ptr <= (nullptr)) /* j6 */; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr <= "") /* j6 */; + // CHECK-FIXES: (void)(*sv_ptr <= "") /* j6 */; (void)(nullptr <= *sv_ptr) /* j7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" <= *sv_ptr) /* j7 */; + // CHECK-FIXES: (void)("" <= *sv_ptr) /* j7 */; (void)((nullptr) <= *sv_ptr) /* j8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" <= *sv_ptr) /* j8 */; + // CHECK-FIXES: (void)("" <= *sv_ptr) /* j8 */; } } @@ -1264,38 +1289,38 @@ void greater_comparison(std::string_view sv) /* k */ { { (void)(sv > nullptr) /* k1 */; // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv > "") /* k1 */; + // CHECK-FIXES: (void)(sv > "") /* k1 */; (void)(sv > (nullptr)) /* k2 */; // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv > "") /* k2 */; + // CHECK-FIXES: (void)(sv > "") /* k2 */; (void)(nullptr > sv) /* k3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" > sv) /* k3 */; + // CHECK-FIXES: (void)("" > sv) /* k3 */; (void)((nullptr) > sv) /* k4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" > sv) /* k4 */; + // CHECK-FIXES: (void)("" > sv) /* k4 */; } // With Equality { (void)(sv >= nullptr) /* k5 */; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv >= "") /* k5 */; + // CHECK-FIXES: (void)(sv >= "") /* k5 */; (void)(sv >= (nullptr)) /* k6 */; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv >= "") /* k6 */; + // CHECK-FIXES: (void)(sv >= "") /* k6 */; (void)(nullptr >= sv) /* k7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" >= sv) /* k7 */; + // CHECK-FIXES: (void)("" >= sv) /* k7 */; (void)((nullptr) >= sv) /* k8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" >= sv) /* k8 */; + // CHECK-FIXES: (void)("" >= sv) /* k8 */; } } @@ -1304,61 +1329,61 @@ void pointer_greater_comparison(std::string_view *sv_ptr) /* l */ { { (void)(*sv_ptr > nullptr) /* l1 */; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr > "") /* l1 */; + // CHECK-FIXES: (void)(*sv_ptr > "") /* l1 */; (void)(*sv_ptr > (nullptr)) /* l2 */; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr > "") /* l2 */; + // CHECK-FIXES: (void)(*sv_ptr > "") /* l2 */; (void)(nullptr > *sv_ptr) /* l3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" > *sv_ptr) /* l3 */; + // CHECK-FIXES: (void)("" > *sv_ptr) /* l3 */; (void)((nullptr) > *sv_ptr) /* l4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" > *sv_ptr) /* l4 */; + // CHECK-FIXES: (void)("" > *sv_ptr) /* l4 */; } // With Equality { (void)(*sv_ptr >= nullptr) /* l5 */; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr >= "") /* l5 */; + // CHECK-FIXES: (void)(*sv_ptr >= "") /* l5 */; (void)(*sv_ptr >= (nullptr)) /* l6 */; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(*sv_ptr >= "") /* l6 */; + // CHECK-FIXES: (void)(*sv_ptr >= "") /* l6 */; (void)(nullptr >= *sv_ptr) /* l7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" >= *sv_ptr) /* l7 */; + // CHECK-FIXES: (void)("" >= *sv_ptr) /* l7 */; (void)((nullptr) >= *sv_ptr) /* l8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)("" >= *sv_ptr) /* l8 */; + // CHECK-FIXES: (void)("" >= *sv_ptr) /* l8 */; } } void relative_comparison_with_temporary(std::string_view sv) /* m */ { (void)(sv < std::string_view(nullptr)) /* m1 */; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv < std::string_view()) /* m1 */; + // CHECK-FIXES: (void)(sv < std::string_view()) /* m1 */; (void)(sv < std::string_view{nullptr}) /* m2 */; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv < std::string_view{}) /* m2 */; + // CHECK-FIXES: (void)(sv < std::string_view{}) /* m2 */; (void)(sv < (std::string_view) nullptr) /* m3 */; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv < (std::string_view) {}) /* m3 */; + // CHECK-FIXES: (void)(sv < (std::string_view) {}) /* m3 */; (void)(sv < (std::string_view){nullptr}) /* m4 */; // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv < (std::string_view){}) /* m4 */; + // CHECK-FIXES: (void)(sv < (std::string_view){}) /* m4 */; (void)(sv < static_cast(nullptr)) /* m5 */; // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv < static_cast("")) /* m5 */; + // CHECK-FIXES: (void)(sv < static_cast("")) /* m5 */; } void equality_comparison(std::string_view sv) /* n */ { @@ -1366,76 +1391,76 @@ void equality_comparison(std::string_view sv) /* n */ { { (void)(sv == nullptr) /* n1 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing basic_string_view to null is undefined; replace with the emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n1 */; + // CHECK-FIXES: (void)(sv.empty()) /* n1 */; (void)(sv == (nullptr)) /* n2 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n2 */; + // CHECK-FIXES: (void)(sv.empty()) /* n2 */; (void)(nullptr == sv) /* n3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n3 */; + // CHECK-FIXES: (void)(sv.empty()) /* n3 */; (void)((nullptr) == sv) /* n4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n4 */; + // CHECK-FIXES: (void)(sv.empty()) /* n4 */; } // Empty With Parens { (void)((sv) == nullptr) /* n5 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing basic_string_view to null is undefined; replace with the emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n5 */; + // CHECK-FIXES: (void)(sv.empty()) /* n5 */; (void)((sv) == (nullptr)) /* n6 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n6 */; + // CHECK-FIXES: (void)(sv.empty()) /* n6 */; (void)(nullptr == (sv)) /* n7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n7 */; + // CHECK-FIXES: (void)(sv.empty()) /* n7 */; (void)((nullptr) == (sv)) /* n8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv.empty()) /* n8 */; + // CHECK-FIXES: (void)(sv.empty()) /* n8 */; } // Non-Empty Without Parens { (void)((sv) != nullptr) /* n9 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n9 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n9 */; (void)((sv) != (nullptr)) /* n10 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n10 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n10 */; (void)(nullptr != (sv)) /* n11 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n11 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n11 */; (void)((nullptr) != (sv)) /* n12 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n12 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n12 */; } // Non-Empty With Parens { (void)((sv) != nullptr) /* n13 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n13 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n13 */; (void)((sv) != (nullptr)) /* n14 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n14 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n14 */; (void)(nullptr != (sv)) /* n15 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n15 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n15 */; (void)((nullptr) != (sv)) /* n16 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv.empty()) /* n16 */; + // CHECK-FIXES: (void)(!sv.empty()) /* n16 */; } } @@ -1444,99 +1469,99 @@ void pointer_equality_comparison(std::string_view *sv_ptr) /* o */ { { (void)(*sv_ptr == nullptr) /* o1 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o1 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o1 */; (void)(*sv_ptr == (nullptr)) /* o2 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o2 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o2 */; (void)(nullptr == *sv_ptr) /* o3 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o3 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o3 */; (void)((nullptr) == *sv_ptr) /* o4 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o4 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o4 */; } // Empty With Parens { (void)((*sv_ptr) == nullptr) /* o5 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o5 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o5 */; (void)((*sv_ptr) == (nullptr)) /* o6 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o6 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o6 */; (void)(nullptr == (*sv_ptr)) /* o7 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o7 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o7 */; (void)((nullptr) == (*sv_ptr)) /* o8 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(sv_ptr->empty()) /* o8 */; + // CHECK-FIXES: (void)(sv_ptr->empty()) /* o8 */; } // Non-Empty With Parens { (void)((*sv_ptr) != nullptr) /* o9 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o9 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o9 */; (void)((*sv_ptr) != (nullptr)) /* o10 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o10 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o10 */; (void)(nullptr != (*sv_ptr)) /* o11 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o11 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o11 */; (void)((nullptr) != (*sv_ptr)) /* o12 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o12 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o12 */; } // Non-Empty Without Parens { (void)((*sv_ptr) != nullptr) /* o13 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o13 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o13 */; (void)((*sv_ptr) != (nullptr)) /* o14 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o14 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o14 */; (void)(nullptr != (*sv_ptr)) /* o15 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o15 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o15 */; (void)((nullptr) != (*sv_ptr)) /* o16 */; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: comparing{{.*}}emptiness query - // CHECK-FIXES: {{^}} (void)(!sv_ptr->empty()) /* o16 */; + // CHECK-FIXES: (void)(!sv_ptr->empty()) /* o16 */; } } void equality_comparison_with_temporary(std::string_view sv) /* p */ { (void)(sv == std::string_view(nullptr)) /* p1 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv == std::string_view()) /* p1 */; + // CHECK-FIXES: (void)(sv == std::string_view()) /* p1 */; (void)(sv == std::string_view{nullptr}) /* p2 */; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv == std::string_view{}) /* p2 */; + // CHECK-FIXES: (void)(sv == std::string_view{}) /* p2 */; (void)(sv == (std::string_view) nullptr) /* p3 */; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv == (std::string_view) {}) /* p3 */; + // CHECK-FIXES: (void)(sv == (std::string_view) {}) /* p3 */; (void)(sv == (std::string_view){nullptr}) /* p4 */; // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} (void)(sv == (std::string_view){}) /* p4 */; + // CHECK-FIXES: (void)(sv == (std::string_view){}) /* p4 */; (void)(sv == static_cast(nullptr)) /* p5 */; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(sv == static_cast("")) /* p5 */; + // CHECK-FIXES: (void)(sv == static_cast("")) /* p5 */; } void return_statement() /* q */ { @@ -1544,54 +1569,55 @@ void return_statement() /* q */ { { []() -> SV { return nullptr; } /* q1 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q1 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q1 */; []() -> SV { return (nullptr); } /* q2 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q2 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q2 */; []() -> SV { return {nullptr}; } /* q3 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q3 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q3 */; []() -> SV { return {(nullptr)}; } /* q4 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q4 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q4 */; []() -> SV { return {{nullptr}}; } /* q5 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q5 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q5 */; []() -> SV { return {{(nullptr)}}; } /* q6 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q6 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q6 */; - []() -> SV { return {{}}; } /* q7 */; // Default `const CharT*` + // Default `const CharT*` + []() -> SV { return {{}}; } /* q7 */; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return {}; } /* q7 */; + // CHECK-FIXES: []() -> SV { return {}; } /* q7 */; } // Return Statement With Temporary { []() -> SV { return SV(nullptr); } /* q8 */; // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return SV(); } /* q8 */; + // CHECK-FIXES: []() -> SV { return SV(); } /* q8 */; []() -> SV { return SV{nullptr}; } /* q9 */; // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return SV{}; } /* q9 */; + // CHECK-FIXES: []() -> SV { return SV{}; } /* q9 */; []() -> SV { return (SV) nullptr; } /* q10 */; // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return (SV) {}; } /* q10 */; + // CHECK-FIXES: []() -> SV { return (SV) {}; } /* q10 */; []() -> SV { return (SV){nullptr}; } /* q11 */; // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: constructing{{.*}}default - // CHECK-FIXES: {{^}} []() -> SV { return (SV){}; } /* q11 */; + // CHECK-FIXES: []() -> SV { return (SV){}; } /* q11 */; []() -> SV { return static_cast(nullptr); } /* q12 */; // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: casting{{.*}}empty string - // CHECK-FIXES: {{^}} []() -> SV { return static_cast(""); } /* q12 */; + // CHECK-FIXES: []() -> SV { return static_cast(""); } /* q12 */; } } @@ -1600,13 +1626,13 @@ void constructor_invocation() /* r */ { explicit AcceptsSV(std::string_view) {} } r1(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} } r1(""); + // CHECK-FIXES: } r1(""); (void)(AcceptsSV{nullptr}) /* r2 */; // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} (void)(AcceptsSV{""}) /* r2 */; + // CHECK-FIXES: (void)(AcceptsSV{""}) /* r2 */; AcceptsSV r3{nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: passing{{.*}}empty string - // CHECK-FIXES: {{^}} AcceptsSV r3{""}; + // CHECK-FIXES: AcceptsSV r3{""}; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp index 969d0bfdf7ed0..4f2acbc2fe7c9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp @@ -1,4 +1,6 @@ -// RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- -- -isystem %clang_tidy_headers -fmodules +// RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- \ +// RUN: -config="{CheckOptions: {bugprone-suspicious-include.IgnoredRegex: 'moc_.*'}"} -- \ +// RUN: -isystem %clang_tidy_headers -fmodules // clang-format off @@ -22,3 +24,6 @@ // CHECK-MESSAGES: [[@LINE+1]]:14: warning: suspicious #include of file with '.cxx' extension # include + +// CHECK-MESSAGES-NOT: warning: +#include "moc_foo.cpp" diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon.cpp index 4f9f4c5db659e..8d87fe00c3e4c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon.cpp @@ -35,7 +35,7 @@ void fail2() if(x == 5); nop(); // CHECK-MESSAGES: :[[@LINE-2]]:12: warning: potentially unintended semicolon [bugprone-suspicious-semicolon] - // CHECK-FIXES: if(x == 5){{$}} + // CHECK-FIXES: if(x == 5) } void fail3() @@ -45,7 +45,7 @@ void fail3() nop(); } // CHECK-MESSAGES: :[[@LINE-4]]:11: warning: potentially unintended semicolon - // CHECK-FIXES: if(x < 5){{$}} + // CHECK-FIXES: if(x < 5) } void correct4() @@ -65,7 +65,7 @@ void fail4() for(int i = 0; i < x; ++i); nop(); // CHECK-MESSAGES: :[[@LINE-2]]:28: warning: potentially unintended semicolon - // CHECK-FIXES: for(int i = 0; i < x; ++i){{$}} + // CHECK-FIXES: for(int i = 0; i < x; ++i) } void fail5() @@ -73,7 +73,7 @@ void fail5() if(x % 5 == 1); nop(); // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: potentially unintended semicolon - // CHECK-FIXES: if(x % 5 == 1){{$}} + // CHECK-FIXES: if(x % 5 == 1) } void fail6() { @@ -82,7 +82,7 @@ void fail6() { } else if (a != 1); a = 2; // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: potentially unintended semicolon - // CHECK-FIXES: } else if (a != 1){{$}} + // CHECK-FIXES: } else if (a != 1) } void fail7() { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-string-compare.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-string-compare.cpp index d670fa9dec70f..399018e16e9a6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-string-compare.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-string-compare.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-suspicious-string-compare %t -- \ +// RUN: %check_clang_tidy %s bugprone-suspicious-string-compare %t -- \ // RUN: -config='{CheckOptions: \ // RUN: {bugprone-suspicious-string-compare.WarnOnImplicitComparison: true, \ // RUN: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison: true}}' \ @@ -117,187 +117,187 @@ int test_implicit_compare_with_functions() { if (memcmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memcmp' is called without explicitly comparing result - // CHECK-FIXES: memcmp(A, "a", 1) != 0) + // CHECK-FIXES: if (memcmp(A, "a", 1) != 0) if (wmemcmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wmemcmp' is called without explicitly comparing result - // CHECK-FIXES: wmemcmp(W, L"a", 1) != 0) + // CHECK-FIXES: if (wmemcmp(W, L"a", 1) != 0) if (memicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memicmp' is called without explicitly comparing result - // CHECK-FIXES: memicmp(A, "a", 1) != 0) + // CHECK-FIXES: if (memicmp(A, "a", 1) != 0) if (_memicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp' is called without explicitly comparing result - // CHECK-FIXES: _memicmp(A, "a", 1) != 0) + // CHECK-FIXES: if (_memicmp(A, "a", 1) != 0) if (_memicmp_l(A, "a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _memicmp_l(A, "a", 1, locale) != 0) + // CHECK-FIXES: if (_memicmp_l(A, "a", 1, locale) != 0) if (strcmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmp' is called without explicitly comparing result - // CHECK-FIXES: strcmp(A, "a") != 0) + // CHECK-FIXES: if (strcmp(A, "a") != 0) if (strncmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncmp' is called without explicitly comparing result - // CHECK-FIXES: strncmp(A, "a", 1) != 0) + // CHECK-FIXES: if (strncmp(A, "a", 1) != 0) if (strcasecmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcasecmp' is called without explicitly comparing result - // CHECK-FIXES: strcasecmp(A, "a") != 0) + // CHECK-FIXES: if (strcasecmp(A, "a") != 0) if (strncasecmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncasecmp' is called without explicitly comparing result - // CHECK-FIXES: strncasecmp(A, "a", 1) != 0) + // CHECK-FIXES: if (strncasecmp(A, "a", 1) != 0) if (stricmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'stricmp' is called without explicitly comparing result - // CHECK-FIXES: stricmp(A, "a") != 0) + // CHECK-FIXES: if (stricmp(A, "a") != 0) if (strcmpi(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmpi' is called without explicitly comparing result - // CHECK-FIXES: strcmpi(A, "a") != 0) + // CHECK-FIXES: if (strcmpi(A, "a") != 0) if (_stricmp(A, "a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp' is called without explicitly comparing result - // CHECK-FIXES: _stricmp(A, "a") != 0) + // CHECK-FIXES: if (_stricmp(A, "a") != 0) if (strnicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strnicmp' is called without explicitly comparing result - // CHECK-FIXES: strnicmp(A, "a", 1) != 0) + // CHECK-FIXES: if (strnicmp(A, "a", 1) != 0) if (_strnicmp(A, "a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp' is called without explicitly comparing result - // CHECK-FIXES: _strnicmp(A, "a", 1) != 0) + // CHECK-FIXES: if (_strnicmp(A, "a", 1) != 0) if (_stricmp_l(A, "a", locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp_l' is called without explicitly comparing result - // CHECK-FIXES: _stricmp_l(A, "a", locale) != 0) + // CHECK-FIXES: if (_stricmp_l(A, "a", locale) != 0) if (_strnicmp_l(A, "a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _strnicmp_l(A, "a", 1, locale) != 0) + // CHECK-FIXES: if (_strnicmp_l(A, "a", 1, locale) != 0) if (wcscmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscmp' is called without explicitly comparing result - // CHECK-FIXES: wcscmp(W, L"a") != 0) + // CHECK-FIXES: if (wcscmp(W, L"a") != 0) if (wcsncmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsncmp' is called without explicitly comparing result - // CHECK-FIXES: wcsncmp(W, L"a", 1) != 0) + // CHECK-FIXES: if (wcsncmp(W, L"a", 1) != 0) if (wcscasecmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscasecmp' is called without explicitly comparing result - // CHECK-FIXES: wcscasecmp(W, L"a") != 0) + // CHECK-FIXES: if (wcscasecmp(W, L"a") != 0) if (wcsicmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsicmp' is called without explicitly comparing result - // CHECK-FIXES: wcsicmp(W, L"a") != 0) + // CHECK-FIXES: if (wcsicmp(W, L"a") != 0) if (_wcsicmp(W, L"a")) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp' is called without explicitly comparing result - // CHECK-FIXES: _wcsicmp(W, L"a") != 0) + // CHECK-FIXES: if (_wcsicmp(W, L"a") != 0) if (_wcsicmp_l(W, L"a", locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _wcsicmp_l(W, L"a", locale) != 0) + // CHECK-FIXES: if (_wcsicmp_l(W, L"a", locale) != 0) if (wcsnicmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsnicmp' is called without explicitly comparing result - // CHECK-FIXES: wcsnicmp(W, L"a", 1) != 0) + // CHECK-FIXES: if (wcsnicmp(W, L"a", 1) != 0) if (_wcsnicmp(W, L"a", 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp' is called without explicitly comparing result - // CHECK-FIXES: _wcsnicmp(W, L"a", 1) != 0) + // CHECK-FIXES: if (_wcsnicmp(W, L"a", 1) != 0) if (_wcsnicmp_l(W, L"a", 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _wcsnicmp_l(W, L"a", 1, locale) != 0) + // CHECK-FIXES: if (_wcsnicmp_l(W, L"a", 1, locale) != 0) if (_mbscmp(U, V)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp' is called without explicitly comparing result - // CHECK-FIXES: _mbscmp(U, V) != 0) + // CHECK-FIXES: if (_mbscmp(U, V) != 0) if (_mbsncmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp' is called without explicitly comparing result - // CHECK-FIXES: _mbsncmp(U, V, 1) != 0) + // CHECK-FIXES: if (_mbsncmp(U, V, 1) != 0) if (_mbsnbcmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp' is called without explicitly comparing result - // CHECK-FIXES: _mbsnbcmp(U, V, 1) != 0) + // CHECK-FIXES: if (_mbsnbcmp(U, V, 1) != 0) if (_mbsnbicmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp' is called without explicitly comparing result - // CHECK-FIXES: _mbsnbicmp(U, V, 1) != 0) + // CHECK-FIXES: if (_mbsnbicmp(U, V, 1) != 0) if (_mbsicmp(U, V)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp' is called without explicitly comparing result - // CHECK-FIXES: _mbsicmp(U, V) != 0) + // CHECK-FIXES: if (_mbsicmp(U, V) != 0) if (_mbsnicmp(U, V, 1)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp' is called without explicitly comparing result - // CHECK-FIXES: _mbsnicmp(U, V, 1) != 0) + // CHECK-FIXES: if (_mbsnicmp(U, V, 1) != 0) if (_mbscmp_l(U, V, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbscmp_l(U, V, locale) != 0) + // CHECK-FIXES: if (_mbscmp_l(U, V, locale) != 0) if (_mbsncmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbsncmp_l(U, V, 1, locale) != 0) + // CHECK-FIXES: if (_mbsncmp_l(U, V, 1, locale) != 0) if (_mbsicmp_l(U, V, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbsicmp_l(U, V, locale) != 0) + // CHECK-FIXES: if (_mbsicmp_l(U, V, locale) != 0) if (_mbsnicmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbsnicmp_l(U, V, 1, locale) != 0) + // CHECK-FIXES: if (_mbsnicmp_l(U, V, 1, locale) != 0) if (_mbsnbcmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbsnbcmp_l(U, V, 1, locale) != 0) + // CHECK-FIXES: if (_mbsnbcmp_l(U, V, 1, locale) != 0) if (_mbsnbicmp_l(U, V, 1, locale)) return 0; // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp_l' is called without explicitly comparing result - // CHECK-FIXES: _mbsnbicmp_l(U, V, 1, locale) != 0) + // CHECK-FIXES: if (_mbsnbicmp_l(U, V, 1, locale) != 0) return 1; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp index 3d21396bf04eb..985ebc2d97736 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/swapped-arguments.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s bugprone-swapped-arguments %t +// RUN: %check_clang_tidy %s bugprone-swapped-arguments %t void F(int, double); @@ -9,7 +9,7 @@ void G(T a, U b) { F(a, b); // no-warning F(2.0, 4); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments. -// CHECK-FIXES: F(4, 2.0) +// CHECK-FIXES: F(4, 2.0); } void funShortFloat(short, float); @@ -20,7 +20,7 @@ void funBoolFloat(bool, float); void foo() { F(1.0, 3); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: argument with implicit conversion from 'double' to 'int' followed by argument converted from 'int' to 'double', potentially swapped arguments. -// CHECK-FIXES: F(3, 1.0) +// CHECK-FIXES: F(3, 1.0); #define M(x, y) x##y() diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp index 824431c1bf52f..8a8973a032bf2 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp @@ -1,5 +1,5 @@ // RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t -- -- -fno-delayed-template-parsing -fexceptions -// CHECK-FIXES: {{^}}#include +// CHECK-FIXES: #include // Ensure that function declarations are not changed. void some_func(int x, double d, bool b, const char *p); @@ -28,48 +28,48 @@ void template_test_function() { T t; int uninitialized; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'uninitialized' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} int uninitialized = 0;{{$}} + // CHECK-FIXES: int uninitialized = 0; } void init_unit_tests() { int x; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'x' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} int x = 0;{{$}} + // CHECK-FIXES: int x = 0; my_int_type myint; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'myint' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} my_int_type myint = 0;{{$}} + // CHECK-FIXES: my_int_type myint = 0; MACRO_INT macroint; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'macroint' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} MACRO_INT macroint = 0;{{$}} + // CHECK-FIXES: MACRO_INT macroint = 0; FULL_DECLARATION(); int x0 = 1, x1, x2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'x1' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} int x0 = 1, x1 = 0, x2 = 2;{{$}} + // CHECK-FIXES: int x0 = 1, x1 = 0, x2 = 2; int y0, y1 = 1, y2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'y0' is not initialized [cppcoreguidelines-init-variables] // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: variable 'y2' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} int y0 = 0, y1 = 1, y2 = 0;{{$}} + // CHECK-FIXES: int y0 = 0, y1 = 1, y2 = 0; int hasval = 42; float f; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'f' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} float f = NAN;{{$}} + // CHECK-FIXES: float f = NAN; float fval = 85.0; double d; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'd' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} double d = NAN;{{$}} + // CHECK-FIXES: double d = NAN; double dval = 99.0; bool b; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: variable 'b' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} bool b = false;{{$}} + // CHECK-FIXES: bool b = false; bool bval = true; const char *ptr; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: variable 'ptr' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} const char *ptr = nullptr;{{$}} + // CHECK-FIXES: const char *ptr = nullptr; const char *ptrval = "a string"; UnusedStruct u; @@ -128,11 +128,11 @@ void uninitialized_enum() { void test_clang_diagnostic_error() { int a; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized [cppcoreguidelines-init-variables] - // CHECK-FIXES: {{^}} int a = 0;{{$}} + // CHECK-FIXES: int a = 0; UnknownType b; // CHECK-MESSAGES: :[[@LINE-1]]:3: error: unknown type name 'UnknownType' [clang-diagnostic-error] - // CHECK-FIXES-NOT: {{^}} UnknownType b = 0;{{$}} + // CHECK-FIXES-NOT: UnknownType b = 0; } namespace gh112089 { @@ -148,3 +148,23 @@ namespace gh112089 { } } // namespace gh112089 +namespace gh161978 { + void test() { + bool (*fp1)(int); + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp1' is not initialized [cppcoreguidelines-init-variables] + // CHECK-FIXES: bool (*fp1)(int) = nullptr; + bool (*fp2)(int, int); + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp2' is not initialized [cppcoreguidelines-init-variables] + // CHECK-FIXES: bool (*fp2)(int, int) = nullptr; + bool (*fp3)(int, int, int); + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp3' is not initialized [cppcoreguidelines-init-variables] + // CHECK-FIXES: bool (*fp3)(int, int, int) = nullptr; + bool (*fp4)(int, int, int, ...); + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp4' is not initialized [cppcoreguidelines-init-variables] + // CHECK-FIXES: bool (*fp4)(int, int, int, ...) = nullptr; + bool (*fp5)(int, int), (*fp6)(int, int); + // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'fp5' is not initialized [cppcoreguidelines-init-variables] + // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: variable 'fp6' is not initialized [cppcoreguidelines-init-variables] + // CHECK-FIXES: bool (*fp5)(int, int) = nullptr, (*fp6)(int, int) = nullptr; + } +} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp index e8d7db17f3c60..2f5e6c7aae653 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s cppcoreguidelines-prefer-member-initializer %t -- -- -fcxx-exceptions +// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t -- -- -fcxx-exceptions extern void __assert_fail (__const char *__assertion, __const char *__file, unsigned int __line, __const char *__function) @@ -398,7 +398,7 @@ class Complex19 { } explicit Complex19(int) { - // CHECK-FIXES: Complex19(int) : n(12) { + // CHECK-FIXES: explicit Complex19(int) : n(12) { n = 12; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer] // CHECK-FIXES: {{^\ *$}} diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index-c++03.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index-c++03.cpp index ad1cc5ab897d9..fe5b5b1514512 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index-c++03.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index-c++03.cpp @@ -1,7 +1,5 @@ // RUN: %check_clang_tidy -std=c++98-or-later %s cppcoreguidelines-pro-bounds-constant-array-index %t -// Note: this test expects no diagnostics, but FileCheck cannot handle that, -// hence the use of | count 0. template struct B { int get() { // The next line used to crash the check (in C++03 mode only). diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp index 6fd52276c2ff1..057ab3b744e22 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s cppcoreguidelines-pro-bounds-constant-array-index %t +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-bounds-constant-array-index %t typedef __SIZE_TYPE__ size_t; @@ -151,7 +151,6 @@ void g() { for (int i = 0; i < 10; ++i) { a[i] = i; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not use array subscript when the index is not an integer constant expression - // CHECK-FIXES: gsl::at(a, i) = i; gsl::at(a, i) = i; // OK, gsl::at() instead of [] } diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-use-assignment.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-use-assignment.cpp index c15d444bd0a66..d1c45ecd35046 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-use-assignment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-use-assignment.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: {cppcoreguidelines-pro-type-member-init.UseAssignment: true}}" -- -fsigned-char +// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: {cppcoreguidelines-pro-type-member-init.UseAssignment: true}}" -- -fsigned-char struct T { int i; @@ -30,7 +30,7 @@ struct S { double d; // CHECK-FIXES: double d = 0.0; long double ld; - // CHECK-FIXES: double ld = 0.0L; + // CHECK-FIXES: long double ld = 0.0L; int *ptr; // CHECK-FIXES: int *ptr = nullptr; T t; diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp index 8896732110583..890d1d262066b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11,c++14,c++17 %s cppcoreguidelines-pro-type-member-init %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s cppcoreguidelines-pro-type-member-init %t -- -- -fno-delayed-template-parsing // FIXME: Fix the checker to work in C++20 mode. struct PositiveFieldBeforeConstructor { @@ -105,7 +105,7 @@ template class NegativeTemplateConstructor { int FIELD; \ }; \ // Ensure FIELD is not initialized since fixes inside of macros are disabled. -// CHECK-FIXES: int FIELD; +// CHECK-FIXES: int FIELD; {{\\}} UNINITIALIZED_FIELD_IN_MACRO_BODY(F); // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F @@ -429,7 +429,7 @@ template struct PositiveTemplateVirtualDestructor; virtual ~UninitializedFieldVirtual##FIELD() {} \ }; \ // Ensure FIELD is not initialized since fixes inside of macros are disabled. -// CHECK-FIXES: int FIELD; +// CHECK-FIXES: int FIELD; {{\\}} UNINITIALIZED_FIELD_IN_MACRO_BODY_VIRTUAL(F); // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp index 44d0251e354a9..725a7094a0f17 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/virtual-class-destructor.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s cppcoreguidelines-virtual-class-destructor %t -- --fix-notes +// RUN: %check_clang_tidy %s cppcoreguidelines-virtual-class-destructor %t -- --fix-notes // CHECK-MESSAGES: :[[@LINE+4]]:8: warning: destructor of 'PrivateVirtualBaseStruct' is private and prevents using the type [cppcoreguidelines-virtual-class-destructor] // CHECK-MESSAGES: :[[@LINE+3]]:8: note: make it public and virtual @@ -163,7 +163,7 @@ class ProtectedNonVirtualClass { // OK // CHECK-FIXES: class OverridingDerivedClass : ProtectedNonVirtualClass { // CHECK-FIXES-NEXT: public: // CHECK-FIXES-NEXT: virtual ~OverridingDerivedClass() = default; -// CHECK-FIXES-NEXT: void f() override; +// CHECK-FIXES-NEXT: void f() override; // is implicitly virtual // CHECK-FIXES-NEXT: }; class OverridingDerivedClass : ProtectedNonVirtualClass { public: @@ -186,7 +186,7 @@ class NonOverridingDerivedClass : ProtectedNonVirtualClass { // CHECK-MESSAGES: :[[@LINE+5]]:8: note: make it public and virtual // CHECK-FIXES: struct OverridingDerivedStruct : ProtectedNonVirtualBaseStruct { // CHECK-FIXES-NEXT: virtual ~OverridingDerivedStruct() = default; -// CHECK-FIXES-NEXT: void f() override; +// CHECK-FIXES-NEXT: void f() override; // is implicitly virtual // CHECK-FIXES-NEXT: }; struct OverridingDerivedStruct : ProtectedNonVirtualBaseStruct { void f() override; // is implicitly virtual @@ -289,26 +289,18 @@ class FooBar2 { virtual CONCAT(~Foo, Bar2()); // FIXME: We should have a fixit for this. }; -// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar3' is protected and virtual [cppcoreguidelines-virtual-class-destructor] -// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual -// CHECK-FIXES: class FooBar3 { -// CHECK-FIXES-NEXT: protected: -// CHECK-FIXES-NEXT: ~FooBar3(); -// CHECK-FIXES-NEXT: }; +// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar3' is protected and virtual [cppcoreguidelines-virtual-class-destructor] +// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual class FooBar3 { protected: - CONCAT(vir, tual) ~FooBar3(); + CONCAT(vir, tual) ~FooBar3(); // FIXME: We should have a fixit for this. }; -// CHECK-MESSAGES: :[[@LINE+6]]:7: warning: destructor of 'FooBar4' is protected and virtual [cppcoreguidelines-virtual-class-destructor] -// CHECK-MESSAGES: :[[@LINE+5]]:7: note: make it protected and non-virtual -// CHECK-FIXES: class FooBar4 { -// CHECK-FIXES-NEXT: protected: -// CHECK-FIXES-NEXT: ~CONCAT(Foo, Bar4()); -// CHECK-FIXES-NEXT: }; +// CHECK-MESSAGES: :[[@LINE+2]]:7: warning: destructor of 'FooBar4' is protected and virtual [cppcoreguidelines-virtual-class-destructor] +// CHECK-MESSAGES: :[[@LINE+1]]:7: note: make it protected and non-virtual class FooBar4 { protected: - CONCAT(vir, tual) ~CONCAT(Foo, Bar4()); + CONCAT(vir, tual) ~CONCAT(Foo, Bar4()); // FIXME: We should have a fixit for this. }; // CHECK-MESSAGES: :[[@LINE+3]]:7: warning: destructor of 'FooBar5' is protected and virtual [cppcoreguidelines-virtual-class-destructor] diff --git a/clang-tools-extra/test/clang-tidy/checkers/zircon/temporary-objects.cpp b/clang-tools-extra/test/clang-tidy/checkers/fuchsia/temporary-objects.cpp similarity index 94% rename from clang-tools-extra/test/clang-tidy/checkers/zircon/temporary-objects.cpp rename to clang-tools-extra/test/clang-tidy/checkers/fuchsia/temporary-objects.cpp index 678992aa50326..916671eef726f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/zircon/temporary-objects.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/fuchsia/temporary-objects.cpp @@ -1,5 +1,5 @@ -// RUN: %check_clang_tidy %s zircon-temporary-objects %t -- \ -// RUN: -config="{CheckOptions: {zircon-temporary-objects.Names: 'Foo;NS::Bar'}}" \ +// RUN: %check_clang_tidy %s fuchsia-temporary-objects %t -- \ +// RUN: -config="{CheckOptions: {fuchsia-temporary-objects.Names: 'Foo;NS::Bar'}}" \ // RUN: -header-filter=.* // Should flag instances of Foo, NS::Bar. diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/build-explicit-make-pair.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/build-explicit-make-pair.cpp index 94d546278eb93..ea77272f97761 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/build-explicit-make-pair.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/build-explicit-make-pair.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s google-build-explicit-make-pair %t +// RUN: %check_clang_tidy %s google-build-explicit-make-pair %t namespace std { template @@ -17,7 +17,7 @@ void templ(T a, T b) { std::make_pair(a, b); std::make_pair(1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair -// CHECK-FIXES: std::make_pair(1, 2) +// CHECK-FIXES: std::make_pair(1, 2); } template @@ -26,15 +26,15 @@ int t(); void test(int i) { std::make_pair(i, i); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, omit template arguments from make_pair -// CHECK-FIXES: std::make_pair(i, i) +// CHECK-FIXES: std::make_pair(i, i); std::make_pair(i, i); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly -// CHECK-FIXES: std::pair(i, i) +// CHECK-FIXES: std::pair(i, i); std::make_pair(i, i); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: for C++11-compatibility, use pair directly -// CHECK-FIXES: std::pair(i, i) +// CHECK-FIXES: std::pair(i, i); #define M std::make_pair(i, i); M diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-nsobject-new.m b/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-nsobject-new.m index f62af8f4c28fe..9d0270284cbcf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-nsobject-new.m +++ b/clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-nsobject-new.m @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s google-objc-avoid-nsobject-new %t +// RUN: %check_clang_tidy %s google-objc-avoid-nsobject-new %t @interface NSObject + (instancetype)new; @@ -25,18 +25,18 @@ @interface NSMutableDictionary<__covariant KeyType, __covariant ObjectType> : NS void CheckSpecificInitRecommendations(void) { NSObject *object = [NSObject new]; // CHECK-MESSAGES: [[@LINE-1]]:22: warning: do not create objects with +new [google-objc-avoid-nsobject-new] - // CHECK-FIXES: [NSObject alloc] init]; + // CHECK-FIXES: NSObject *object = {{[[][[]}}NSObject alloc] init]; NSDate *correctDate = [NSDate date]; NSDate *incorrectDate = [NSDate new]; // CHECK-MESSAGES: [[@LINE-1]]:27: warning: do not create objects with +new [google-objc-avoid-nsobject-new] - // CHECK-FIXES: [NSDate date]; + // CHECK-FIXES: NSDate *incorrectDate = [NSDate date]; NSObject *macroCreated = ALLOCATE_OBJECT(NSObject); // Shouldn't warn on macros. NSMutableDictionary *dict = [NSMutableDictionary new]; // CHECK-MESSAGES: [[@LINE-1]]:31: warning: do not create objects with +new [google-objc-avoid-nsobject-new] - // CHECK-FIXES: [NSMutableDictionary alloc] init]; + // CHECK-FIXES: NSMutableDictionary *dict = {{[[][[]}}NSMutableDictionary alloc] init]; } @interface Foo : NSObject diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments.cpp index 963449a213e53..d555b878ae4c0 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments.cpp @@ -75,7 +75,7 @@ void h(); // CHECK-MESSAGES: :[[@LINE+2]]:1: warning: anonymous namespace not terminated with // CHECK-MESSAGES: :[[@LINE-10]]:26: note: anonymous namespace starts here } -// CHECK-FIXES: } // namespace{{$}} +// CHECK-FIXES: } // namespace namespace [[]] { void hh(); @@ -89,7 +89,7 @@ void hh(); // CHECK-MESSAGES: :[[@LINE+2]]:1: warning: anonymous namespace not terminated with // CHECK-MESSAGES: :[[@LINE-10]]:16: note: anonymous namespace starts here } -// CHECK-FIXES: } // namespace{{$}} +// CHECK-FIXES: } // namespace namespace short1 { namespace short2 { diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp b/clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp index cf24d2d533240..edb11b9863532 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/google/upgrade-googletest-case.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s google-upgrade-googletest-case %t -- -- -I%S/Inputs +// RUN: %check_clang_tidy %s google-upgrade-googletest-case %t -- -- -I%S/Inputs // RUN: %check_clang_tidy -check-suffix=NOSUITE %s google-upgrade-googletest-case %t -- -- -DNOSUITE -I%S/Inputs/gtest/nosuite #include "gtest/gtest.h" @@ -89,12 +89,14 @@ template class FooTypedTest : public testing::Test { // CHECK-FIXES: static void TearDownTestSuite(); }; -template void FooTypedTest::SetUpTestCase() {} -// CHECK-MESSAGES: [[@LINE-1]]:45: warning: Google Test APIs named with 'case' +template +void FooTypedTest::SetUpTestCase() {} +// CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case' // CHECK-FIXES: void FooTypedTest::SetUpTestSuite() {} -template void FooTypedTest::TearDownTestCase() {} -// CHECK-MESSAGES: [[@LINE-1]]:45: warning: Google Test APIs named with 'case' +template +void FooTypedTest::TearDownTestCase() {} +// CHECK-MESSAGES: [[@LINE-1]]:23: warning: Google Test APIs named with 'case' // CHECK-FIXES: void FooTypedTest::TearDownTestSuite() {} class BarTest : public testing::Test { diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-isa-or-dyn-cast-in-conditionals.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-isa-or-dyn-cast-in-conditionals.cpp index 6b4c917f6c599..4edcc05d46e10 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-isa-or-dyn-cast-in-conditionals.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-isa-or-dyn-cast-in-conditionals.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s llvm-prefer-isa-or-dyn-cast-in-conditionals %t +// RUN: %check_clang_tidy %s llvm-prefer-isa-or-dyn-cast-in-conditionals %t struct X; struct Y; @@ -79,7 +79,7 @@ bool foo(Y *y, Z *z) { break; } while (cast(y)); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: cast<> in conditional - // CHECK-FIXES: while (isa(y)); + // CHECK-FIXES: } while (isa(y)); if (dyn_cast(y)) return true; @@ -100,7 +100,7 @@ bool foo(Y *y, Z *z) { break; } while (dyn_cast(y)); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return value from dyn_cast<> not used - // CHECK-FIXES: while (isa(y)); + // CHECK-FIXES: } while (isa(y)); if (y && isa(y)) return true; diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned.cpp index 5dd3a9de7c910..07b4f33919db9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/prefer-register-over-unsigned.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s llvm-prefer-register-over-unsigned %t +// RUN: %check_clang_tidy %s llvm-prefer-register-over-unsigned %t namespace llvm { class Register { @@ -23,8 +23,8 @@ llvm::RegisterLike getRegLike(); void apply_1() { unsigned Reg1 = getReg(); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'Reg1' declared as 'unsigned int'; use 'llvm::Register' instead [llvm-prefer-register-over-unsigned] - // CHECK-FIXES: apply_1() - // CHECK-FIXES-NEXT: llvm::Register Reg1 = getReg(); + // CHECK-FIXES: void apply_1() { + // CHECK-FIXES-NEXT: llvm::Register Reg1 = getReg(); } void apply_2() { @@ -34,110 +34,110 @@ void apply_2() { // DeclContext for the function so we can't elide the llvm:: in this // case. Fortunately, it doesn't actually occur in the LLVM code base. // CHECK-MESSAGES: :[[@LINE-4]]:12: warning: variable 'Reg2' declared as 'unsigned int'; use 'llvm::Register' instead [llvm-prefer-register-over-unsigned] - // CHECK-FIXES: apply_2() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: llvm::Register Reg2 = getReg(); + // CHECK-FIXES: void apply_2() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: llvm::Register Reg2 = getReg(); } namespace llvm { void apply_3() { unsigned Reg3 = getReg(); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'Reg3' declared as 'unsigned int'; use 'Register' instead [llvm-prefer-register-over-unsigned] - // CHECK-FIXES: apply_3() - // CHECK-FIXES-NEXT: Register Reg3 = getReg(); + // CHECK-FIXES: void apply_3() { + // CHECK-FIXES-NEXT: Register Reg3 = getReg(); } } // end namespace llvm void done_1() { llvm::Register Reg1 = getReg(); - // CHECK-FIXES: done_1() - // CHECK-FIXES-NEXT: llvm::Register Reg1 = getReg(); + // CHECK-FIXES: void done_1() { + // CHECK-FIXES-NEXT: llvm::Register Reg1 = getReg(); } void done_2() { using namespace llvm; Register Reg2 = getReg(); - // CHECK-FIXES: done_2() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: Register Reg2 = getReg(); + // CHECK-FIXES: void done_2() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: Register Reg2 = getReg(); } namespace llvm { void done_3() { Register Reg3 = getReg(); - // CHECK-FIXES: done_3() - // CHECK-FIXES-NEXT: Register Reg3 = getReg(); + // CHECK-FIXES: void done_3() { + // CHECK-FIXES-NEXT: Register Reg3 = getReg(); } } // end namespace llvm void do_nothing_1() { unsigned Reg1 = getRegLike(); - // CHECK-FIXES: do_nothing_1() - // CHECK-FIXES-NEXT: unsigned Reg1 = getRegLike(); + // CHECK-FIXES: void do_nothing_1() { + // CHECK-FIXES-NEXT: unsigned Reg1 = getRegLike(); } void do_nothing_2() { using namespace llvm; unsigned Reg2 = getRegLike(); - // CHECK-FIXES: do_nothing_2() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: unsigned Reg2 = getRegLike(); + // CHECK-FIXES: void do_nothing_2() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: unsigned Reg2 = getRegLike(); } namespace llvm { void do_nothing_3() { unsigned Reg3 = getRegLike(); - // CHECK-FIXES: do_nothing_3() - // CHECK-FIXES-NEXT: unsigned Reg3 = getRegLike(); + // CHECK-FIXES: void do_nothing_3() { + // CHECK-FIXES-NEXT: unsigned Reg3 = getRegLike(); } } // end namespace llvm void fn1(llvm::Register R); void do_nothing_4() { fn1(getReg()); - // CHECK-FIXES: do_nothing_4() - // CHECK-FIXES-NEXT: fn1(getReg()); + // CHECK-FIXES: void do_nothing_4() { + // CHECK-FIXES-NEXT: fn1(getReg()); } void fn2(unsigned R); void do_nothing_5() { fn2(getReg()); - // CHECK-FIXES: do_nothing_5() - // CHECK-FIXES-NEXT: fn2(getReg()); + // CHECK-FIXES: void do_nothing_5() { + // CHECK-FIXES-NEXT: fn2(getReg()); } void do_nothing_6() { using namespace llvm; Register Reg6{getReg()}; - // CHECK-FIXES: do_nothing_6() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: Register Reg6{getReg()}; + // CHECK-FIXES: void do_nothing_6() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: Register Reg6{getReg()}; } void do_nothing_7() { using namespace llvm; Register Reg7; Reg7.Reg = getReg(); - // CHECK-FIXES: do_nothing_7() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: Register Reg7; - // CHECK-FIXES-NEXT: Reg7.Reg = getReg(); + // CHECK-FIXES: void do_nothing_7() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: Register Reg7; + // CHECK-FIXES-NEXT: Reg7.Reg = getReg(); } void do_nothing_8() { using namespace llvm; RegisterLike Reg8{getReg()}; - // CHECK-FIXES: do_nothing_8() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: RegisterLike Reg8{getReg()}; + // CHECK-FIXES: void do_nothing_8() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: RegisterLike Reg8{getReg()}; } void do_nothing_9() { using namespace llvm; RegisterLike Reg9; Reg9.Reg = getReg(); - // CHECK-FIXES: do_nothing_9() - // CHECK-FIXES-NEXT: using namespace llvm; - // CHECK-FIXES-NEXT: RegisterLike Reg9; - // CHECK-FIXES-NEXT: Reg9.Reg = getReg(); + // CHECK-FIXES: void do_nothing_9() { + // CHECK-FIXES-NEXT: using namespace llvm; + // CHECK-FIXES-NEXT: RegisterLike Reg9; + // CHECK-FIXES-NEXT: Reg9.Reg = getReg(); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/twine-local.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/twine-local.cpp index 05c9971252e71..be64029d5c740 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/llvm/twine-local.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/twine-local.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s llvm-twine-local %t +// RUN: %check_clang_tidy %s llvm-twine-local %t namespace llvm { class Twine { @@ -24,7 +24,7 @@ int main() { const Twine t = Twine("a") + "b" + Twine(42); // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t = (Twine("a") + "b" + Twine(42)).str(); +// CHECK-FIXES: const std::string t = (Twine("a") + "b" + Twine(42)).str(); foo(Twine("a") + "b"); Twine Prefix = false ? "__INT_FAST" : "__UINT_FAST"; @@ -35,31 +35,31 @@ int main() { const Twine t2 = Twine(); // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t2 = (Twine()).str(); +// CHECK-FIXES: const std::string t2 = (Twine()).str(); foo(Twine() + "b"); const Twine t3 = Twine(42); // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t3 = (Twine(42)).str(); +// CHECK-FIXES: const std::string t3 = (Twine(42)).str(); const Twine t4 = Twine(42) + "b"; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t4 = (Twine(42) + "b").str(); +// CHECK-FIXES: const std::string t4 = (Twine(42) + "b").str(); const Twine t5 = Twine() + "b"; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t5 = (Twine() + "b").str(); +// CHECK-FIXES: const std::string t5 = (Twine() + "b").str(); const Twine t6 = true ? Twine() : Twine(42); // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t6 = (true ? Twine() : Twine(42)).str(); +// CHECK-FIXES: const std::string t6 = (true ? Twine() : Twine(42)).str(); const Twine t7 = false ? Twine() : Twine("b"); // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs // CHECK-MESSAGES: note: FIX-IT applied suggested code changes -// CHECK-FIXES: std::string t7 = (false ? Twine() : Twine("b")).str(); +// CHECK-FIXES: const std::string t7 = (false ? Twine() : Twine("b")).str(); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp index 0971a1611e3cb..b57eab089c748 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s llvm-use-new-mlir-op-builder %t +// RUN: %check_clang_tidy %s llvm-use-new-mlir-op-builder %t namespace mlir { class Location {}; @@ -36,25 +36,24 @@ struct NamedOp { template void g(mlir::OpBuilder &b) { // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] - // CHECK-FIXES: T::create(b, b.getUnknownLoc(), "gaz") + // CHECK-FIXES: T::create(b, b.getUnknownLoc(), "gaz"); b.create(b.getUnknownLoc(), "gaz"); } void f() { mlir::OpBuilder builder; // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] - // CHECK-FIXES: mlir:: ModuleOp::create(builder, builder.getUnknownLoc()) + // CHECK-FIXES: mlir:: ModuleOp::create(builder, builder.getUnknownLoc()); builder.create(builder.getUnknownLoc()); using mlir::NamedOp; // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] - // CHECK-FIXES: NamedOp::create(builder, builder.getUnknownLoc(), "baz") + // CHECK-FIXES: NamedOp::create(builder, builder.getUnknownLoc(), "baz"); builder.create(builder.getUnknownLoc(), "baz"); - // CHECK-MESSAGES: :[[@LINE+4]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] - // CHECK-FIXES: NamedOp::create(builder, - // CHECK-FIXES: builder.getUnknownLoc(), - // CHECK-FIXES: "caz") + // CHECK-MESSAGES: :[[@LINE+3]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] + // CHECK-FIXES: NamedOp::create(builder, builder.getUnknownLoc(), + // CHECK-FIXES: "caz"); builder. create( builder.getUnknownLoc(), @@ -67,7 +66,7 @@ void f() { mlir::ImplicitLocOpBuilder ib; // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] - // CHECK-FIXES: mlir::ModuleOp::create(ib) + // CHECK-FIXES: mlir::ModuleOp::create(ib); ib.create( ); // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create(...)' [llvm-use-new-mlir-op-builder] diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp index bcd946e7404c1..e20680ceeefa5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s misc-const-correctness %t \ +// RUN: %check_clang_tidy %s misc-const-correctness %t \ // RUN: -config='{CheckOptions: {\ // RUN: misc-const-correctness.AnalyzeValues: false,\ // RUN: misc-const-correctness.AnalyzeReferences: false,\ @@ -14,7 +14,7 @@ void pointee_to_const() { int a[] = {1, 2}; int *p_local0 = &a[0]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *' can be declared 'const' - // CHECK-FIXES: int const*p_local0 + // CHECK-FIXES: int const*p_local0 = &a[0]; p_local0 = &a[1]; } @@ -22,7 +22,7 @@ void array_of_pointer_to_const() { int a[] = {1, 2}; int *p_local0[1] = {&a[0]}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'int *[1]' can be declared 'const' - // CHECK-FIXES: int const*p_local0[1] + // CHECK-FIXES: int const*p_local0[1] = {&a[0]}; p_local0[0] = &a[1]; } @@ -31,7 +31,7 @@ void template_fn() { T a[] = {1, 2}; T *p_local0 = &a[0]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: pointee of variable 'p_local0' of type 'char *' can be declared 'const' - // CHECK-FIXES: T const*p_local0 + // CHECK-FIXES: T const*p_local0 = &a[0]; p_local0 = &a[1]; } @@ -48,6 +48,11 @@ void ignore_const_alias() { p_local0 = &a[1]; } +void function_pointer_basic() { + void (*const fp)() = nullptr; + fp(); +} + void takeNonConstRef(int *&r); void ignoreNonConstRefOps() { diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp index 74be3dccc9daa..02d32c0ec73e5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s misc-const-correctness %t \ +// RUN: %check_clang_tidy %s misc-const-correctness %t \ // RUN: -config='{CheckOptions: \ // RUN: {misc-const-correctness.AnalyzeValues: true,\ // RUN: misc-const-correctness.WarnPointersAsValues: true,\ @@ -10,32 +10,31 @@ void potential_const_pointer() { double np_local0[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; double *p_local0 = &np_local0[1]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double *' can be declared 'const' - // CHECK-FIXES: double *const p_local0 + // CHECK-FIXES: double *const p_local0 = &np_local0[1]; using doublePtr = double*; using doubleArray = double[15]; doubleArray np_local1; doublePtr p_local1 = &np_local1[0]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'doublePtr' (aka 'double *') can be declared 'const' - // CHECK-FIXES: doublePtr const p_local1 + // CHECK-FIXES: doublePtr const p_local1 = &np_local1[0]; } void range_for() { int np_local0[2] = {1, 2}; int *p_local0[2] = {&np_local0[0], &np_local0[1]}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[2]' can be declared 'const' - // CHECK-FIXES: int *const p_local0[2] + // CHECK-FIXES: int *const p_local0[2] = {&np_local0[0], &np_local0[1]}; for (const int *p_local1 : p_local0) { // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local1' of type 'const int *' can be declared 'const' - // CHECK-FIXES: for (const int *const p_local1 : p_local0) + // CHECK-FIXES: for (const int *const p_local1 : p_local0) { } int *p_local2[2] = {nullptr, nullptr}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int *[2]' can be declared 'const' - // CHECK-FIXES: int *const p_local2[2] + // CHECK-FIXES: int *const p_local2[2] = {nullptr, nullptr}; for (const auto *con_ptr : p_local2) { } - } template @@ -59,7 +58,7 @@ void EmitProtocolMethodList(T &&Methods) { // some expressions are type-dependent. SmallVector p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'SmallVector' can be declared 'const' - // CHECK-FIXES: SmallVector const p_local0 + // CHECK-FIXES: SmallVector const p_local0; SmallVector np_local0; for (const auto *I : Methods) { if (I == nullptr) @@ -70,6 +69,6 @@ void EmitProtocolMethodList(T &&Methods) { void instantiate() { int *p_local0[4] = {nullptr, nullptr, nullptr, nullptr}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int *[4]' can be declared 'const' - // CHECK-FIXES: int *const p_local0[4] + // CHECK-FIXES: int *const p_local0[4] = {nullptr, nullptr, nullptr, nullptr}; EmitProtocolMethodList(p_local0); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp index 17dcf12e2536c..4cef7f4ce116e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s misc-const-correctness %t -- \ +// RUN: %check_clang_tidy %s misc-const-correctness %t -- \ // RUN: -config="{CheckOptions: {\ // RUN: misc-const-correctness.TransformValues: true, \ // RUN: misc-const-correctness.WarnPointersAsValues: false, \ @@ -38,7 +38,7 @@ void some_function(double, wchar_t); void some_function(double np_arg0, wchar_t np_arg1) { int p_local0 = 2; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 2; int np_local0; const int np_local1 = 42; @@ -60,7 +60,7 @@ void some_function(double np_arg0, wchar_t np_arg1) { int function_try_block() try { int p_local0 = 0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 0; return p_local0; } catch (...) { return 0; @@ -69,13 +69,13 @@ int function_try_block() try { void nested_scopes() { int p_local0 = 2; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 2; int np_local0 = 42; { int p_local1 = 42; // CHECK-MESSAGES: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: int const p_local1 = 42; np_local0 *= 2; } } @@ -89,7 +89,7 @@ void some_lambda_environment_capture_all_by_reference(double np_arg0) { int np_local0 = 0; int p_local0 = 1; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 1; int np_local2; const int np_local3 = 2; @@ -99,14 +99,14 @@ void some_lambda_environment_capture_all_by_reference(double np_arg0) { int p_local1 = 0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: int const p_local1 = 0; } void some_lambda_environment_capture_all_by_value(double np_arg0) { int np_local0 = 0; int p_local0 = 1; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 1; int np_local1; const int np_local2 = 2; @@ -139,12 +139,12 @@ void some_pointer_taking(int *out) { int p_local1 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: int const p_local1 = 42; const int *const p0_p_local1 = &p_local1; int p_local2 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local2 + // CHECK-FIXES: int const p_local2 = 42; function_in_pointer(&p_local2); } @@ -163,19 +163,19 @@ void some_reference_taking() { int p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 42; const int &r0_p_local0 = p_local0; int p_local1 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: int const p_local1 = 42; function_in_ref(p_local1); } double *non_const_pointer_return() { double p_local0 = 0.0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local0 + // CHECK-FIXES: double const p_local0 = 0.0; double np_local0 = 24.4; return &np_local0; @@ -184,10 +184,10 @@ double *non_const_pointer_return() { const double *const_pointer_return() { double p_local0 = 0.0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local0 + // CHECK-FIXES: double const p_local0 = 0.0; double p_local1 = 24.4; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local1 + // CHECK-FIXES: double const p_local1 = 24.4; return &p_local1; } @@ -195,10 +195,10 @@ const double *const_pointer_return() { const double &const_ref_return() { double p_local0 = 0.0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local0 + // CHECK-FIXES: double const p_local0 = 0.0; double p_local1 = 24.4; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local1 + // CHECK-FIXES: double const p_local1 = 24.4; return p_local1; } @@ -237,7 +237,7 @@ void define_locals(T np_arg0, T &np_arg1, int np_arg2) { // non-template values are ok still. int p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 42; np_local4 += p_local0; } @@ -306,19 +306,19 @@ void direct_class_access() { ConstNonConstClass p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'ConstNonConstClass' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local0 + // CHECK-FIXES: ConstNonConstClass const p_local0; p_local0.constMethod(); ConstNonConstClass p_local1; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'ConstNonConstClass' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local1 + // CHECK-FIXES: ConstNonConstClass const p_local1; double np_local1; p_local1.modifyingMethod(np_local1); double np_local2; ConstNonConstClass p_local2(np_local2); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'ConstNonConstClass' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local2(np_local2) + // CHECK-FIXES: ConstNonConstClass const p_local2(np_local2); ConstNonConstClass np_local3; np_local3.NonConstMember = 42.; @@ -328,14 +328,14 @@ void direct_class_access() { ConstNonConstClass p_local3; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'ConstNonConstClass' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local3 + // CHECK-FIXES: ConstNonConstClass const p_local3; const double val0 = p_local3.NonConstMember; const double val1 = p_local3.NonConstMemberRef; const double val2 = *p_local3.NonConstMemberPtr; ConstNonConstClass p_local4; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local4' of type 'ConstNonConstClass' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local4 + // CHECK-FIXES: ConstNonConstClass const p_local4; *np_local4.NonConstMemberPtr = 42.; } @@ -347,7 +347,7 @@ void class_access_array() { ConstNonConstClass p_local0[2]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'ConstNonConstClass[2]' can be declared 'const' - // CHECK-FIXES: ConstNonConstClass const p_local0[2] + // CHECK-FIXES: ConstNonConstClass const p_local0[2]; p_local0[0].constMethod(); np_local0[1].constMethod(); } @@ -367,10 +367,10 @@ void internal_operator_calls() { OperatorsAsConstAsPossible np_local1; OperatorsAsConstAsPossible p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'OperatorsAsConstAsPossible' can be declared 'const' - // CHECK-FIXES: OperatorsAsConstAsPossible const p_local0 + // CHECK-FIXES: OperatorsAsConstAsPossible const p_local0; OperatorsAsConstAsPossible p_local1; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'OperatorsAsConstAsPossible' can be declared 'const' - // CHECK-FIXES: OperatorsAsConstAsPossible const p_local1 + // CHECK-FIXES: OperatorsAsConstAsPossible const p_local1; np_local0 += p_local0; np_local1 = p_local0 + p_local1; @@ -383,10 +383,10 @@ void internal_operator_calls() { NonConstOperators p_local2; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'NonConstOperators' can be declared 'const' - // CHECK-FIXES: NonConstOperators const p_local2 + // CHECK-FIXES: NonConstOperators const p_local2; NonConstOperators p_local3 = p_local2 - p_local2; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'NonConstOperators' can be declared 'const' - // CHECK-FIXES: NonConstOperators const p_local3 + // CHECK-FIXES: NonConstOperators const p_local3 = p_local2 - p_local2; } struct MyVector { @@ -411,17 +411,17 @@ void vector_usage() { double p_local0[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local0[10] + // CHECK-FIXES: double const p_local0[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; double p_local1 = p_local0[5]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local1 + // CHECK-FIXES: double const p_local1 = p_local0[5]; - // The following subscript calls suprisingly choose the non-const operator + // The following subscript calls surprisingly choose the non-const operator // version. MyVector np_local2; double p_local2 = np_local2[42]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local2 + // CHECK-FIXES: double const p_local2 = np_local2[42]; MyVector np_local3; const double np_local4 = np_local3[42]; @@ -430,7 +430,7 @@ void vector_usage() { const MyVector np_local5{}; double p_local3 = np_local5[42]; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'double' can be declared 'const' - // CHECK-FIXES: double const p_local3 + // CHECK-FIXES: double const p_local3 = np_local5[42]; } void const_handle(const double &np_local0); @@ -460,27 +460,27 @@ void handle_from_array() { // Constant handles are ok double p_local1[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local1[10] + // CHECK-FIXES: double const p_local1[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; const double *p_local2 = &p_local1[2]; // Could be `const double *const`, but warning deactivated by default double p_local3[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local3[10] + // CHECK-FIXES: double const p_local3[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; const double &const_ref = p_local3[2]; double p_local4[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local4' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local4[10] + // CHECK-FIXES: double const p_local4[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; const double *const_ptr; const_ptr = &p_local4[2]; double p_local5[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local5' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local5[10] + // CHECK-FIXES: double const p_local5[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; const_handle(p_local5[2]); double p_local6[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local6' of type 'double[10]' can be declared 'const' - // CHECK-FIXES: double const p_local6[10] + // CHECK-FIXES: double const p_local6[10] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9.}; const_handle(&p_local6[2]); } @@ -513,15 +513,15 @@ void range_for() { int p_local0[2] = {1, 2}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int[2]' can be declared 'const' - // CHECK-FIXES: int const p_local0[2] + // CHECK-FIXES: int const p_local0[2] = {1, 2}; for (int value : p_local0) { // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'value' of type 'int' can be declared 'const' - // CHECK-FIXES: int const value + // CHECK-FIXES: for (int const value : p_local0) { } int p_local1[2] = {1, 2}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int[2]' can be declared 'const' - // CHECK-FIXES: int const p_local1[2] + // CHECK-FIXES: int const p_local1[2] = {1, 2}; for (const int &const_ref : p_local1) { } } @@ -552,7 +552,7 @@ void conversion_operators() { ModifyingConversion np_local0; NonModifyingConversion p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'NonModifyingConversion' can be declared 'const' - // CHECK-FIXES: NonModifyingConversion const p_local0 + // CHECK-FIXES: NonModifyingConversion const p_local0; int np_local1 = np_local0; np_local1 = p_local0; @@ -561,16 +561,16 @@ void conversion_operators() { void casts() { decltype(sizeof(void *)) p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'decltype(sizeof(void *))' - // CHECK-FIXES: decltype(sizeof(void *)) const p_local0 + // CHECK-FIXES: decltype(sizeof(void *)) const p_local0 = 42; auto np_local0 = reinterpret_cast(p_local0); np_local0 = nullptr; int p_local1 = 43; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: int const p_local1 = 43; short p_local2 = static_cast(p_local1); // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'short' can be declared 'const' - // CHECK-FIXES: short const p_local2 + // CHECK-FIXES: short const p_local2 = static_cast(p_local1); int np_local1 = p_local2; int &np_local2 = static_cast(np_local1); @@ -584,7 +584,7 @@ void ternary_operator() { int p_local0 = 3, np_local3 = 5; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-NOT-FIXES: int const p_local0 = 3 + // CHECK-NOT-FIXES: int const p_local0 = 3, np_local3 = 5; const int &np_local4 = true ? p_local0 : ++np_local3; int np_local5[3] = {1, 2, 3}; @@ -636,13 +636,13 @@ struct TMPClass { void meta_type() { TMPClass p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'TMPClass' can be declared 'const' - // CHECK-FIXES: TMPClass const p_local0 + // CHECK-FIXES: TMPClass const p_local0; p_local0.alwaysConst(); p_local0.sometimesConst(); TMPClass p_local1; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'TMPClass' can be declared 'const' - // CHECK-FIXES: TMPClass const p_local1 + // CHECK-FIXES: TMPClass const p_local1; p_local1.alwaysConst(); TMPClass np_local0; @@ -659,7 +659,7 @@ template void placement_new_in_unique_ptr() { int p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 42; int np_local0 = p_local0; new to_construct(np_local0); } @@ -696,7 +696,7 @@ void TestRegisters() { HardwareRegister p_reg1{3, 22}; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_reg1' of type 'HardwareRegister' can be declared 'const' - // CHECK-FIXES: HardwareRegister const p_reg1 + // CHECK-FIXES: HardwareRegister const p_reg1{3, 22}; const unsigned p_val = p_reg1.another; } @@ -745,7 +745,7 @@ struct A { void f() { int p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 42; int np_local0 = 42; f_signature action = my_alloc; action(np_local0); @@ -795,7 +795,7 @@ void for_bad_iterators() { non_const_iterator np_local3; for (int p_local0 : np_local3) // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: for (int const p_local0 : np_local3) ; // Horrible code constructs... @@ -805,21 +805,21 @@ void for_bad_iterators() { non_const_iterator np_local5; for (int p_local1 : np_local4, np_local5) // CHECK-MESSAGES: [[@LINE-1]]:10: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: for (int const p_local1 : np_local4, np_local5) ; non_const_iterator np_local6; non_const_iterator np_local7; for (int p_local2 : 1 > 2 ? np_local6 : np_local7) // CHECK-MESSAGES: [[@LINE-1]]:10: warning: variable 'p_local2' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local2 + // CHECK-FIXES: for (int const p_local2 : 1 > 2 ? np_local6 : np_local7) ; non_const_iterator np_local8; non_const_iterator np_local9; for (int p_local3 : 2 > 1 ? np_local8 : (np_local8, np_local9)) // CHECK-MESSAGES: [[@LINE-1]]:10: warning: variable 'p_local3' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local3 + // CHECK-FIXES: for (int const p_local3 : 2 > 1 ? np_local8 : (np_local8, np_local9)) ; } } @@ -836,23 +836,23 @@ struct good_iterator { void good_iterators() { good_iterator p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'good_iterator' can be declared 'const' - // CHECK-FIXES: good_iterator const p_local0 + // CHECK-FIXES: good_iterator const p_local0; good_iterator &p_local1 = p_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'good_iterator &' can be declared 'const' - // CHECK-FIXES: good_iterator const&p_local1 + // CHECK-FIXES: good_iterator const&p_local1 = p_local0; for (int p_local2 : p_local1) { // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local2' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local2 + // CHECK-FIXES: for (int const p_local2 : p_local1) { (void)p_local2; } good_iterator p_local3; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local3' of type 'good_iterator' can be declared 'const' - // CHECK-FIXES: good_iterator const p_local3 + // CHECK-FIXES: good_iterator const p_local3; for (int p_local4 : p_local3) // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local4' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local4 + // CHECK-FIXES: for (int const p_local4 : p_local3) ; good_iterator np_local1; for (int &np_local2 : np_local1) @@ -871,11 +871,11 @@ void for_ok_iterators_array() { int np_local0[42]; int(&p_local0)[42] = np_local0; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int (&)[42]' can be declared 'const' - // CHECK-FIXES: int const(&p_local0)[42] + // CHECK-FIXES: int const(&p_local0)[42] = np_local0; for (int p_local1 : p_local0) { // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local1' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local1 + // CHECK-FIXES: for (int const p_local1 : p_local0) { (void)p_local1; } } @@ -891,7 +891,7 @@ void complex_usage() { int np_local0 = 42; int p_local0 = 42; // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const' - // CHECK-FIXES: int const p_local0 + // CHECK-FIXES: int const p_local0 = 42; int np_local1 = 42; (np_local0 == p_local0 ? np_local0 : (p_local0, np_local1))++; } @@ -920,7 +920,7 @@ void create_false_positive() { int np_local0 = 42; list_init p_local0 = {np_local0}; // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'p_local0' of type 'list_init' can be declared 'const' - // CHECK-FIXES: list_init const p_local0 + // CHECK-FIXES: list_init const p_local0 = {np_local0}; } struct list_init_derived { base &member; @@ -929,7 +929,7 @@ void list_init_derived_func() { derived np_local0; list_init_derived p_local0 = {np_local0}; // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'p_local0' of type 'list_init_derived' can be declared 'const' - // CHECK-FIXES: list_init_derived const p_local0 + // CHECK-FIXES: list_init_derived const p_local0 = {np_local0}; } template struct ref_pair { @@ -945,7 +945,7 @@ void cast_in_class_hierarchy() { derived np_local0; base p_local1 = static_cast(np_local0); // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'p_local1' of type 'base' can be declared 'const' - // CHECK-FIXES: base const p_local1 + // CHECK-FIXES: base const p_local1 = static_cast(np_local0); } void function_ref_target(int); diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp index c48a2ee9276be..853ec77a90351 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s misc-definitions-in-headers %t -- --fix-notes +// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- --fix-notes int f() { // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers] @@ -25,7 +25,7 @@ class CA { void CA::f2() { } // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: function 'f2' defined in a header file; -// CHECK-FIXES: inline void CA::f2() { +// CHECK-FIXES: inline void CA::f2() { } template <> int CA::f3() { diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-wrong-config.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-wrong-config.cpp index 11ce59f3a4ce9..fdcb811707241 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-wrong-config.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-wrong-config.cpp @@ -7,4 +7,4 @@ // CHECK-MESSAGES: warning: The check 'misc-include-cleaner' will not perform any analysis because 'UnusedIncludes' and 'MissingIncludes' are both false. [clang-tidy-config] #include "bar.h" -// CHECK-FIXES-NOT: {{^}}#include "baz.h"{{$}} +// CHECK-FIXES-NOT: #include "baz.h" diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp index e10ac3f46e2e9..3db0efaa73244 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp @@ -1,10 +1,10 @@ // RUN: %check_clang_tidy %s misc-include-cleaner %t -- -- -I%S/Inputs -isystem%S/Inputs/system #include "bar.h" -// CHECK-FIXES: {{^}}#include "baz.h"{{$}} +// CHECK-FIXES: #include "baz.h" #include "foo.h" // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: included header foo.h is not used directly [misc-include-cleaner] // CHECK-FIXES: {{^}} -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: included header vector.h is not used directly [misc-include-cleaner] // CHECK-FIXES: {{^}} diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression.cpp index 95d8ecb15a4f1..4ff0ba867ebb9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/redundant-expression.cpp @@ -999,21 +999,21 @@ int TestOperatorConfusion(int X, int Y, long Z) int K = !(1 | 2 | 4); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: ineffective logical negation operator used; did you mean '~'? - // CHECK-FIXES: {{^}} int K = ~(1 | 2 | 4);{{$}} + // CHECK-FIXES: int K = ~(1 | 2 | 4); K = !(FLAG1 & FLAG2 & FLAG3); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: ineffective logical negation operator - // CHECK-FIXES: {{^}} K = ~(FLAG1 & FLAG2 & FLAG3);{{$}} + // CHECK-FIXES: K = ~(FLAG1 & FLAG2 & FLAG3); K = !(3 | 4); // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: ineffective logical negation operator - // CHECK-FIXES: {{^}} K = ~(3 | 4);{{$}} + // CHECK-FIXES: K = ~(3 | 4); int NotFlags = !FLAGS; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: ineffective logical negation operator - // CHECK-FIXES: {{^}} int NotFlags = ~FLAGS;{{$}} + // CHECK-FIXES: int NotFlags = ~FLAGS; NotFlags = NOTFLAGS; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: ineffective logical negation operator return !(1 | 2 | 4); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: ineffective logical negation operator - // CHECK-FIXES: {{^}} return ~(1 | 2 | 4);{{$}} + // CHECK-FIXES: return ~(1 | 2 | 4); } template diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp index 319cefa1c68f1..56d1306c3633a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-strict.cpp @@ -5,14 +5,14 @@ namespace strict_mode { void f(int foo) {} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'foo' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void f(int /*foo*/) {}{{$}} +// CHECK-FIXES: void f(int /*foo*/) {} class E { int i; public: E(int j) {} // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'j' is unused -// CHECK-FIXES: {{^}} E(int /*j*/) {}{{$}} +// CHECK-FIXES: E(int /*j*/) {} }; class F { int i; @@ -20,7 +20,7 @@ class F { public: F(int j) : i() {} // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'j' is unused -// CHECK-FIXES: {{^}} F(int /*j*/) : i() {}{{$}} +// CHECK-FIXES: F(int /*j*/) : i() {} }; // Do not warn on naked functions. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c index e2f501c708f01..994dfa1c0486f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.c @@ -4,14 +4,14 @@ // ============= void a(int i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void a(int i) {;}{{$}} +// CHECK-FIXES: void a(int i) {;} #if __STDC_VERSION__ < 202311L static void b(); // In C before C23, forward declarations can leave out parameters. #endif static void b(int i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}static void b() {;}{{$}} +// CHECK-FIXES: static void b() {;} // Unchanged cases // =============== diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp index c963cb5b21940..f473f26a48e8c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters.cpp @@ -1,7 +1,7 @@ // RUN: mkdir -p %t.dir // RUN: echo "static void staticFunctionHeader(int i) {;}" > %t.dir/header.h // RUN: echo "static void staticFunctionHeader(int /*i*/) {;}" > %t.dir/header-fixed.h -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11 %s misc-unused-parameters %t.dir/code -- -header-filter='.*' -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy -std=c++11 %s misc-unused-parameters %t.dir/code -- -header-filter='.*' -- -fno-delayed-template-parsing // RUN: diff %t.dir/header.h %t.dir/header-fixed.h // FIXME: Make the test work in all language modes. @@ -11,36 +11,36 @@ // ============= void a(int i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void a(int /*i*/) {;}{{$}} +// CHECK-FIXES: void a(int /*i*/) {;} void b(int i = 1) {;} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void b(int /*i*/ = 1) {;}{{$}} +// CHECK-FIXES: void b(int /*i*/ = 1) {;} void c(int *i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void c(int * /*i*/) {;}{{$}} +// CHECK-FIXES: void c(int * /*i*/) {;} void d(int i[]) {;} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void d(int /*i*/[]) {;}{{$}} +// CHECK-FIXES: void d(int /*i*/[]) {;} void e(int i[1]) {;} // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void e(int /*i*/[1]) {;}{{$}} +// CHECK-FIXES: void e(int /*i*/[1]) {;} void f(void (*fn)()) {;} // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}void f(void (* /*fn*/)()) {;}{{$}} +// CHECK-FIXES: void f(void (* /*fn*/)()) {;} int *k([[clang::lifetimebound]] int *i) { return nullptr; } // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) { return nullptr; }{{$}} +// CHECK-FIXES: int *k({{\[\[clang::lifetimebound\]\]}} int * /*i*/) { return nullptr; } #define ATTR_BEFORE(x) [[clang::lifetimebound]] x int* m(ATTR_BEFORE(const int *i)) { return nullptr; } // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: parameter 'i' is unused [misc-unused-parameters] -// CHECK-FIXES: {{^}}int* m(ATTR_BEFORE(const int * /*i*/)) { return nullptr; }{{$}} +// CHECK-FIXES: int* m(ATTR_BEFORE(const int * /*i*/)) { return nullptr; } #undef ATTR_BEFORE // Unchanged cases @@ -64,44 +64,44 @@ static bool static_var = useLambda([] (int a) { return a; }); // Remove parameters of local functions // ==================================== static void staticFunctionA(int i); -// CHECK-FIXES: {{^}}static void staticFunctionA(); +// CHECK-FIXES: static void staticFunctionA(); static void staticFunctionA(int i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning -// CHECK-FIXES: {{^}}static void staticFunctionA() +// CHECK-FIXES: static void staticFunctionA() {;} static void staticFunctionB(int i, int j) { (void)i; } // CHECK-MESSAGES: :[[@LINE-1]]:40: warning -// CHECK-FIXES: {{^}}static void staticFunctionB(int i) +// CHECK-FIXES: static void staticFunctionB(int i) { (void)i; } static void staticFunctionC(int i, int j) { (void)j; } // CHECK-MESSAGES: :[[@LINE-1]]:33: warning -// CHECK-FIXES: {{^}}static void staticFunctionC(int j) +// CHECK-FIXES: static void staticFunctionC(int j) { (void)j; } static void staticFunctionD(int i, int j, int k) { (void)i; (void)k; } // CHECK-MESSAGES: :[[@LINE-1]]:40: warning -// CHECK-FIXES: {{^}}static void staticFunctionD(int i, int k) +// CHECK-FIXES: static void staticFunctionD(int i, int k) { (void)i; (void)k; } static void staticFunctionE(int i = 4) {;} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning -// CHECK-FIXES: {{^}}static void staticFunctionE() +// CHECK-FIXES: static void staticFunctionE() {;} static void staticFunctionF(int i = 4); -// CHECK-FIXES: {{^}}static void staticFunctionF(); +// CHECK-FIXES: static void staticFunctionF(); static void staticFunctionF(int i) {;} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning -// CHECK-FIXES: {{^}}static void staticFunctionF() +// CHECK-FIXES: static void staticFunctionF() {;} static void staticFunctionG(int i[]); -// CHECK-FIXES: {{^}}static void staticFunctionG(); +// CHECK-FIXES: static void staticFunctionG(); static void staticFunctionG(int i[]) {;} // CHECK-MESSAGES: :[[@LINE-1]]:33: warning -// CHECK-FIXES: {{^}}static void staticFunctionG() +// CHECK-FIXES: static void staticFunctionG() {;} static void staticFunctionH(void (*fn)()); -// CHECK-FIXES: {{^}}static void staticFunctionH(); +// CHECK-FIXES: static void staticFunctionH(); static void staticFunctionH(void (*fn)()) {;} // CHECK-MESSAGES: :[[@LINE-1]]:36: warning -// CHECK-FIXES: {{^}}static void staticFunctionH() +// CHECK-FIXES: static void staticFunctionH() {;} static void someCallSites() { staticFunctionA(1); @@ -136,12 +136,12 @@ static void someCallSites() { // ======================================================= static int variableWithLongName1(int LongName1, int LongName2) { // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: parameter 'LongName2' is unused -// CHECK-FIXES: {{^}}static int variableWithLongName1(int LongName1) { +// CHECK-FIXES: static int variableWithLongName1(int LongName1) { return LongName1; } static int variableWithLongName2(int LongName1, int LongName2) { // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: parameter 'LongName1' is unused -// CHECK-FIXES: {{^}}static int variableWithLongName2(int LongName2) { +// CHECK-FIXES: static int variableWithLongName2(int LongName2) { return LongName2; } static void someLongNameCallSites() { @@ -225,12 +225,12 @@ template void someFunctionTemplate(T b, T e) { (void)b; (void)e; } template void someFunctionTemplateOneUnusedParam(T b, T e) { (void)e; } // CHECK-MESSAGES: :[[@LINE-1]]:65: warning -// CHECK-FIXES: {{^}}template void someFunctionTemplateOneUnusedParam(T /*b*/, T e) { (void)e; } +// CHECK-FIXES: template void someFunctionTemplateOneUnusedParam(T /*b*/, T e) { (void)e; } template void someFunctionTemplateAllUnusedParams(T b, T e) {;} // CHECK-MESSAGES: :[[@LINE-1]]:66: warning // CHECK-MESSAGES: :[[@LINE-2]]:71: warning -// CHECK-FIXES: {{^}}template void someFunctionTemplateAllUnusedParams(T /*b*/, T /*e*/) {;} +// CHECK-FIXES: template void someFunctionTemplateAllUnusedParams(T /*b*/, T /*e*/) {;} static void dontGetConfusedByParametersInFunctionTypes() { void (*F)(int i); } @@ -244,7 +244,7 @@ namespace { struct a { void b(int c) {;} // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: parameter 'c' is unused -// CHECK-FIXES: {{^}} void b() {;}{{$}} +// CHECK-FIXES: void b() {;} }; template class d { @@ -262,7 +262,7 @@ void f2(int foo2) { } void f3(int foo3) {;} // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'foo3' is unused -// CHECK-FIXES: {{^}}void f3(int /*foo3*/) {;}{{$}} +// CHECK-FIXES: void f3(int /*foo3*/) {;} class E { int i; @@ -277,7 +277,7 @@ class F { // Constructor initializer counts as a non-empty body. F(int j) : i() {} // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'j' is unused -// CHECK-FIXES: {{^}} F(int /*j*/) : i() {}{{$}} +// CHECK-FIXES: F(int /*j*/) : i() {} }; class A { @@ -289,7 +289,7 @@ class B : public A { public: B(int i) : A() {} // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is unused -// CHECK-FIXES: {{^}} B(int /*i*/) : A() {}{{$}} +// CHECK-FIXES: B(int /*i*/) : A() {} }; } // namespace strict_mode_off @@ -298,7 +298,7 @@ using fn = void(int); void f(fn *); void test() { // CHECK-MESSAGES: :[[@LINE+2]]:12: warning: parameter 'I' is unused - // CHECK-FIXES: {{^}} f([](int /*I*/) { + // CHECK-FIXES: f([](int /*I*/) { return; }); f([](int I) { return; }); } } // namespace lambda diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-cxx17.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-cxx17.cpp index 69e9cf7e3d3f7..ac11218ec82a8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-cxx17.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-cxx17.cpp @@ -22,7 +22,7 @@ using ns::Bar; using ns::Foo; using ns::Unused; // Unused // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: using decl 'Unused' is unused -// CHECK-FIXES: {{^}}// Unused +// CHECK-FIXES: // Unused void f() { Foo(123); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp index 342c96a6b947f..6aa7d48bc9d05 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++14-or-later %s modernize-avoid-bind %t +// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-avoid-bind %t namespace std { inline namespace impl { @@ -229,19 +229,19 @@ void testFunctionObjects() { D *e = nullptr; auto AAA = std::bind(d, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto AAA = [d] { d(1, 2); } + // CHECK-FIXES: auto AAA = [d] { d(1, 2); }; auto BBB = std::bind(*e, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto BBB = [e] { (*e)(1, 2); } + // CHECK-FIXES: auto BBB = [e] { (*e)(1, 2); }; auto CCC = std::bind(D{}, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto CCC = [] { D{}(1, 2); } + // CHECK-FIXES: auto CCC = [] { D{}(1, 2); }; auto DDD = std::bind(D(), 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto DDD = [] { D()(1, 2); } + // CHECK-FIXES: auto DDD = [] { D()(1, 2); }; auto EEE = std::bind(*D::create(), 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: prefer a lambda to std::bind @@ -384,11 +384,11 @@ struct E { auto III = std::bind(&D::operator(), d, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto III = [d] { (*d)(1, 2); } + // CHECK-FIXES: auto III = [d] { (*d)(1, 2); }; auto JJJ = std::bind(&D::operator(), &dd, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto JJJ = [ObjectPtr = &dd] { (*ObjectPtr)(1, 2); } + // CHECK-FIXES: auto JJJ = [ObjectPtr = &dd] { (*ObjectPtr)(1, 2); }; auto KKK = std::bind(&D::operator(), _1, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind @@ -396,11 +396,11 @@ struct E { auto LLL = std::bind(&D::operator bool, d); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto LLL = [d] { return d->operator bool(); } + // CHECK-FIXES: auto LLL = [d] { return d->operator bool(); }; auto MMM = std::bind(&E::operator(), this, 1, 2); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind - // CHECK-FIXES: auto MMM = [this] { return (*this)(1, 2); } + // CHECK-FIXES: auto MMM = [this] { return (*this)(1, 2); }; } }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp index 78adbebfe548d..35cb5503ba245 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp @@ -1,10 +1,10 @@ // RUN: mkdir -p %t.dir // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %t.dir/modernize-concat-nested-namespaces.h -// RUN: %check_clang_tidy --match-partial-fixes -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t.dir/code -- -header-filter=".*" -- -I %t.dir +// RUN: %check_clang_tidy -std=c++17 -check-suffix=NORMAL %s modernize-concat-nested-namespaces %t.dir/code -- -header-filter=".*" -- -I %t.dir // RUN: FileCheck -input-file=%t.dir/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES // Restore header file and re-run with c++20: // RUN: cp %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h %t.dir/modernize-concat-nested-namespaces.h -// RUN: %check_clang_tidy --match-partial-fixes -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t.dir/code -- -header-filter=".*" -- -I %t.dir +// RUN: %check_clang_tidy -std=c++20 -check-suffixes=NORMAL,CPP20 %s modernize-concat-nested-namespaces %t.dir/code -- -header-filter=".*" -- -I %t.dir // RUN: FileCheck -input-file=%t.dir/modernize-concat-nested-namespaces.h %S/Inputs/concat-nested-namespaces/modernize-concat-nested-namespaces.h -check-prefix=CHECK-FIXES #include "modernize-concat-nested-namespaces.h" @@ -38,16 +38,16 @@ void t(); namespace n9 { namespace n10 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n9::n10 +// CHECK-FIXES-NORMAL: namespace n9::n10 { void t(); } // namespace n10 } // namespace n9 -// CHECK-FIXES-NORMAL: } +// CHECK-FIXES-NORMAL: } // namespace n9::n10 namespace n11 { namespace n12 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n11::n12 +// CHECK-FIXES-NORMAL: namespace n11::n12 { namespace n13 { void t(); } @@ -71,7 +71,7 @@ namespace n18 { namespace n19 { namespace n20 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-3]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n18::n19::n20 +// CHECK-FIXES-NORMAL: namespace n18::n19::n20 { void t(); } // namespace n20 } // namespace n19 @@ -94,11 +94,11 @@ namespace { namespace n24 { namespace n25 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n24::n25 +// CHECK-FIXES-NORMAL: namespace n24::n25 { void t(); } // namespace n25 } // namespace n24 -// CHECK-FIXES-NORMAL: } +// CHECK-FIXES-NORMAL: } // namespace n24::n25 } // namespace } // namespace n23 @@ -136,7 +136,7 @@ void t(); namespace n39 { namespace n40 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n39::n40 +// CHECK-FIXES-NORMAL: namespace n39::n40 { #ifdef IEXIST void t() {} #endif @@ -147,7 +147,7 @@ void t() {} namespace n41 { namespace n42 { // CHECK-MESSAGES-NORMAL-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces] -// CHECK-FIXES-NORMAL: namespace n41::n42 +// CHECK-FIXES-NORMAL: namespace n41::n42 { #ifdef IDONTEXIST void t() {} #endif diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx03.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx03.cpp index f01d6a677e27b..b02dfd1ce976f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx03.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx03.cpp @@ -2,69 +2,69 @@ #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'assert.h'; consider using 'cassert' instead [modernize-deprecated-headers] -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'complex.h'; consider using 'complex' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'ctype.h'; consider using 'cctype' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'errno.h'; consider using 'cerrno' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'float.h'; consider using 'cfloat' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'limits.h'; consider using 'climits' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'locale.h'; consider using 'clocale' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'setjmp.h'; consider using 'csetjmp' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'signal.h'; consider using 'csignal' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdarg.h'; consider using 'cstdarg' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdio.h'; consider using 'cstdio' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'string.h'; consider using 'cstring' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'time.h'; consider using 'ctime' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wchar.h'; consider using 'cwchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wctype.h'; consider using 'cwctype' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include // Headers that have no effect in C++; remove them #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdalign.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdbool.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'iso646.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // // Headers deprecated since C++11: expect no diagnostics. #include @@ -76,69 +76,69 @@ #include "assert.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'assert.h'; consider using 'cassert' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "complex.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'complex.h'; consider using 'complex' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "ctype.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'ctype.h'; consider using 'cctype' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "errno.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'errno.h'; consider using 'cerrno' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "float.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'float.h'; consider using 'cfloat' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "limits.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'limits.h'; consider using 'climits' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "locale.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'locale.h'; consider using 'clocale' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "math.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "setjmp.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'setjmp.h'; consider using 'csetjmp' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "signal.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'signal.h'; consider using 'csignal' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdarg.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdarg.h'; consider using 'cstdarg' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stddef.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdio.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdio.h'; consider using 'cstdio' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdlib.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "string.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'string.h'; consider using 'cstring' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "time.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'time.h'; consider using 'ctime' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "wchar.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wchar.h'; consider using 'cwchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "wctype.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wctype.h'; consider using 'cwctype' instead -// CHECK-FIXES: {{^}}#include +// CHECK-FIXES: #include // Headers that have no effect in C++; remove them #include "stdalign.h" // "stdalign.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdalign.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "stdalign.h"{{$}} +// CHECK-FIXES: // "stdalign.h" #include "stdbool.h" // "stdbool.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdbool.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "stdbool.h"{{$}} +// CHECK-FIXES: // "stdbool.h" #include "iso646.h" // "iso646.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'iso646.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "iso646.h"{{$}} +// CHECK-FIXES: // "iso646.h" // Headers deprecated since C++11; expect no diagnostics #include "fenv.h" diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx11.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx11.cpp index 29c5dc4eb9762..99ef506276a66 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx11.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/deprecated-headers-cxx11.cpp @@ -2,162 +2,162 @@ #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'assert.h'; consider using 'cassert' instead [modernize-deprecated-headers] -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'complex.h'; consider using 'complex' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'ctype.h'; consider using 'cctype' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'errno.h'; consider using 'cerrno' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'fenv.h'; consider using 'cfenv' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'float.h'; consider using 'cfloat' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'inttypes.h'; consider using 'cinttypes' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'limits.h'; consider using 'climits' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'locale.h'; consider using 'clocale' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'setjmp.h'; consider using 'csetjmp' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'signal.h'; consider using 'csignal' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdarg.h'; consider using 'cstdarg' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdio.h'; consider using 'cstdio' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'string.h'; consider using 'cstring' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'tgmath.h'; consider using 'ctgmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'time.h'; consider using 'ctime' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'uchar.h'; consider using 'cuchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wchar.h'; consider using 'cwchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wctype.h'; consider using 'cwctype' instead -// CHECK-FIXES: {{^}}#include +// CHECK-FIXES: #include // Headers that have no effect in C++; remove them #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdalign.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdbool.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // #include // // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'iso646.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// {{$}} +// CHECK-FIXES: // #include "assert.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'assert.h'; consider using 'cassert' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "complex.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'complex.h'; consider using 'complex' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "ctype.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'ctype.h'; consider using 'cctype' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "errno.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'errno.h'; consider using 'cerrno' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "fenv.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'fenv.h'; consider using 'cfenv' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "float.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'float.h'; consider using 'cfloat' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "inttypes.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'inttypes.h'; consider using 'cinttypes' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "limits.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'limits.h'; consider using 'climits' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "locale.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'locale.h'; consider using 'clocale' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "math.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "setjmp.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'setjmp.h'; consider using 'csetjmp' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "signal.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'signal.h'; consider using 'csignal' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdarg.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdarg.h'; consider using 'cstdarg' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stddef.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stddef.h'; consider using 'cstddef' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdint.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdint.h'; consider using 'cstdint' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdio.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdio.h'; consider using 'cstdio' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "stdlib.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'stdlib.h'; consider using 'cstdlib' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "string.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'string.h'; consider using 'cstring' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "tgmath.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'tgmath.h'; consider using 'ctgmath' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "time.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'time.h'; consider using 'ctime' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "uchar.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'uchar.h'; consider using 'cuchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "wchar.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wchar.h'; consider using 'cwchar' instead -// CHECK-FIXES: {{^}}#include {{$}} +// CHECK-FIXES: #include #include "wctype.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: inclusion of deprecated C++ header 'wctype.h'; consider using 'cwctype' instead -// CHECK-FIXES: {{^}}#include +// CHECK-FIXES: #include // Headers that have no effect in C++; remove them #include "stdalign.h" // "stdalign.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdalign.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "stdalign.h"{{$}} +// CHECK-FIXES: // "stdalign.h" #include "stdbool.h" // "stdbool.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'stdbool.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "stdbool.h"{{$}} +// CHECK-FIXES: // "stdbool.h" #include "iso646.h" // "iso646.h" // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: including 'iso646.h' has no effect in C++; consider removing it -// CHECK-FIXES: {{^}}// "iso646.h"{{$}} +// CHECK-FIXES: // "iso646.h" diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp index 419e7f899066d..2f744eb8f1c9b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-loop-convert %t -- -- -I %S/Inputs/loop-convert +// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I %S/Inputs/loop-convert #include "structures.h" @@ -18,7 +18,7 @@ void f() { int K; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: Sum += I; // CHECK-FIXES-NEXT: int K; @@ -27,7 +27,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -36,7 +36,7 @@ void f() { int Y = Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: int X = I; // CHECK-FIXES-NEXT: int Y = I + 2; @@ -45,7 +45,7 @@ void f() { X = Arr[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: int X = N; // CHECK-FIXES-NEXT: X = I; @@ -53,7 +53,7 @@ void f() { Arr[I] += 1; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: I += 1; for (int I = 0; I < N; ++I) { @@ -61,7 +61,7 @@ void f() { Arr[I]++; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: int X = I + 2; // CHECK-FIXES-NEXT: I++; @@ -69,14 +69,14 @@ void f() { Arr[I] = 4 + Arr[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: I = 4 + I; for (int I = 0; I < NMinusOne + 1; ++I) { Sum += Arr[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: Sum += I; for (int I = 0; I < N; ++I) { @@ -84,7 +84,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -96,7 +96,7 @@ void f() { size += sizeof((Matrix[I])); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Matrix) + // CHECK-FIXES: for (auto & I : Matrix) { // CHECK-FIXES-NEXT: size += sizeof(I); // CHECK-FIXES-NEXT: size += sizeof I; // CHECK-FIXES-NEXT: size += sizeof(I); @@ -106,7 +106,7 @@ void f() { Teas[I].g(); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Tea : Teas) + // CHECK-FIXES: for (auto & Tea : Teas) { // CHECK-FIXES-NEXT: Tea.g(); for (int I = 0; N > I; ++I) { @@ -114,7 +114,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -123,7 +123,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -132,7 +132,7 @@ void f() { Sum += Arr[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: printf("Fibonacci number %d has address %p\n", I, &I); // CHECK-FIXES-NEXT: Sum += I + 2; } @@ -142,7 +142,7 @@ const int *constArray() { printf("2 * %d = %d\n", ConstArr[I], ConstArr[I] + ConstArr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : ConstArr) + // CHECK-FIXES: for (int I : ConstArr) { // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I, I + I); const NonTriviallyCopyable NonCopy[N]{}; @@ -150,7 +150,7 @@ const int *constArray() { printf("2 * %d = %d\n", NonCopy[I].X, NonCopy[I].X + NonCopy[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : NonCopy) + // CHECK-FIXES: for (const auto & I : NonCopy) { // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X); const TriviallyCopyableButBig Big[N]{}; @@ -158,7 +158,7 @@ const int *constArray() { printf("2 * %d = %d\n", Big[I].X, Big[I].X + Big[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : Big) + // CHECK-FIXES: for (const auto & I : Big) { // CHECK-FIXES-NEXT: printf("2 * %d = %d\n", I.X, I.X + I.X); bool Something = false; @@ -167,7 +167,7 @@ const int *constArray() { return &ConstArr[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const int & I : ConstArr) + // CHECK-FIXES: for (const int & I : ConstArr) { // CHECK-FIXES-NEXT: if (Something) // CHECK-FIXES-NEXT: return &I; @@ -182,14 +182,14 @@ struct HasArr { printf("%d", Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: printf("%d", I); for (int I = 0; I < N; ++I) { printf("%d", ValArr[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : ValArr) + // CHECK-FIXES: for (auto & I : ValArr) { // CHECK-FIXES-NEXT: printf("%d", I.X); } @@ -198,14 +198,14 @@ struct HasArr { printf("%d", this->Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : this->Arr) + // CHECK-FIXES: for (int I : this->Arr) { // CHECK-FIXES-NEXT: printf("%d", I); for (int I = 0; I < N; ++I) { printf("%d", this->ValArr[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : this->ValArr) + // CHECK-FIXES: for (auto & I : this->ValArr) { // CHECK-FIXES-NEXT: printf("%d", I.X); } }; @@ -217,14 +217,14 @@ struct HasIndirectArr { printf("%d", HA.Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : HA.Arr) + // CHECK-FIXES: for (int I : HA.Arr) { // CHECK-FIXES-NEXT: printf("%d", I); for (int I = 0; I < N; ++I) { printf("%d", HA.ValArr[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : HA.ValArr) + // CHECK-FIXES: for (auto & I : HA.ValArr) { // CHECK-FIXES-NEXT: printf("%d", I.X); } @@ -233,14 +233,14 @@ struct HasIndirectArr { printf("%d", this->HA.Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : this->HA.Arr) + // CHECK-FIXES: for (int I : this->HA.Arr) { // CHECK-FIXES-NEXT: printf("%d", I); for (int I = 0; I < N; ++I) { printf("%d", this->HA.ValArr[I].X); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : this->HA.ValArr) + // CHECK-FIXES: for (auto & I : this->HA.ValArr) { // CHECK-FIXES-NEXT: printf("%d", I.X); } }; @@ -285,7 +285,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Tt) + // CHECK-FIXES: for (int & It : Tt) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); // Do not crash because of Qq.begin() converting. Q::iterator converts with a @@ -295,7 +295,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Qq) + // CHECK-FIXES: for (int & It : Qq) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); T *Pt; @@ -303,7 +303,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : *Pt) + // CHECK-FIXES: for (int & It : *Pt) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); S Ss; @@ -311,7 +311,7 @@ void f() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); S *Ps; @@ -319,42 +319,42 @@ void f() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & P : *Ps) + // CHECK-FIXES: for (auto & P : *Ps) { // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X); for (S::const_iterator It = Ss.cbegin(), E = Ss.cend(); It != E; ++It) { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto It : Ss) + // CHECK-FIXES: for (auto It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { printf("s has value %d\n", It->X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { It->X = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.X = 3; for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { (*It).X = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.X = 3; for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) { It->nonConstFun(4, 5); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.nonConstFun(4, 5); U Uu; @@ -362,14 +362,14 @@ void f() { printf("s has value %d\n", It->X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Uu) + // CHECK-FIXES: for (auto & It : Uu) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Uu) + // CHECK-FIXES: for (auto & It : Uu) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (U::iterator It = Uu.begin(), E = Uu.end(); It != E; ++It) { @@ -389,7 +389,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : V) + // CHECK-FIXES: for (int & It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); for (dependent::iterator It(V.begin()), E = V.end(); @@ -397,7 +397,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : V) + // CHECK-FIXES: for (int & It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); doublyDependent Intmap; @@ -406,7 +406,7 @@ void f() { printf("Intmap[%d] = %d", It->first, It->second); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Intmap) + // CHECK-FIXES: for (auto & It : Intmap) { // CHECK-FIXES: printf("Intmap[%d] = %d", It.first, It.second); // PtrSet's iterator dereferences by value so auto & can't be used. @@ -418,7 +418,7 @@ void f() { (void) *I; } // CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Val_int_ptr : Val_int_ptrs) + // CHECK-FIXES: for (auto Val_int_ptr : Val_int_ptrs) { } // This container uses an iterator where the dereference type is a typedef of @@ -432,7 +432,7 @@ void f() { (void) *I; } // CHECK-MESSAGES: :[[@LINE-5]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int & Int_ptr : Int_ptrs) + // CHECK-FIXES: for (int & Int_ptr : Int_ptrs) { } { @@ -451,49 +451,49 @@ void f() { printf("%d\n", (**I).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Dpp) + // CHECK-FIXES: for (auto & I : Dpp) { // CHECK-FIXES-NEXT: printf("%d\n", (*I).X); for (dependent::iterator I = Dpp.begin(), E = Dpp.end(); I != E; ++I) { printf("%d\n", (*I)->X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Dpp) + // CHECK-FIXES: for (auto & I : Dpp) { // CHECK-FIXES-NEXT: printf("%d\n", I->X); for (S::iterator It = begin(Ss), E = end(Ss); It != E; ++It) { printf("s0 has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s0 has value %d\n", It.X); for (S::iterator It = std::begin(Ss), E = std::end(Ss); It != E; ++It) { printf("s1 has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s1 has value %d\n", It.X); for (S::iterator It = begin(*Ps), E = end(*Ps); It != E; ++It) { printf("s2 has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : *Ps) + // CHECK-FIXES: for (auto & It : *Ps) { // CHECK-FIXES-NEXT: printf("s2 has value %d\n", It.X); for (S::iterator It = begin(*Ps); It != end(*Ps); ++It) { printf("s3 has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : *Ps) + // CHECK-FIXES: for (auto & It : *Ps) { // CHECK-FIXES-NEXT: printf("s3 has value %d\n", It.X); for (S::const_iterator It = cbegin(Ss), E = cend(Ss); It != E; ++It) { printf("s4 has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto It : Ss) + // CHECK-FIXES: for (auto It : Ss) { // CHECK-FIXES-NEXT: printf("s4 has value %d\n", It.X); } @@ -507,7 +507,7 @@ void different_type() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto It : Ss) + // CHECK-FIXES: for (auto It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); S *Ps; @@ -515,7 +515,7 @@ void different_type() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto P : *Ps) + // CHECK-FIXES: for (auto P : *Ps) { // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X); dependent V; @@ -524,7 +524,7 @@ void different_type() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int It : V) + // CHECK-FIXES: for (int It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); for (dependent::const_iterator It(V.begin()), E = V.end(); @@ -532,7 +532,7 @@ void different_type() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int It : V) + // CHECK-FIXES: for (int It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); } @@ -634,7 +634,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -643,7 +643,7 @@ void f() { Sum += V.at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -652,7 +652,7 @@ void f() { Sum += Pv->at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : *Pv) + // CHECK-FIXES: for (int I : *Pv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -665,7 +665,7 @@ void f() { Sum += (*Pv)[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : *Pv) + // CHECK-FIXES: for (int I : *Pv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -674,7 +674,7 @@ void f() { Sum += Cv->at(I) + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : *Cv) + // CHECK-FIXES: for (int I : *Cv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -683,7 +683,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -692,7 +692,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -701,7 +701,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -710,7 +710,7 @@ void f() { Sum += VD[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : VD) + // CHECK-FIXES: for (int I : VD) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -719,7 +719,7 @@ void f() { Sum += V[I] + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2; @@ -727,14 +727,14 @@ void f() { V[I] = 0; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : V) + // CHECK-FIXES: for (int & I : V) { // CHECK-FIXES-NEXT: I = 0; for (int I = 0, E = std::size(V); E != I; ++I) { V[I] = 0; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : V) + // CHECK-FIXES: for (int & I : V) { // CHECK-FIXES-NEXT: I = 0; // Although 'length' might be a valid free function, only size() is standardized @@ -748,7 +748,7 @@ void f() { Sum += Vals[I].X; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Val : Vals) + // CHECK-FIXES: for (auto & Val : Vals) { // CHECK-FIXES-NEXT: Sum += Val.X; } @@ -760,7 +760,7 @@ void constness() { Sum += Constv[I].X + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : Constv) + // CHECK-FIXES: for (const auto & I : Constv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X); // CHECK-FIXES-NEXT: Sum += I.X + 2; @@ -769,7 +769,7 @@ void constness() { Sum += Constv.at(I).X + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : Constv) + // CHECK-FIXES: for (const auto & I : Constv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X); // CHECK-FIXES-NEXT: Sum += I.X + 2; @@ -778,7 +778,7 @@ void constness() { Sum += Pconstv->at(I).X + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : *Pconstv) + // CHECK-FIXES: for (const auto & I : *Pconstv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X); // CHECK-FIXES-NEXT: Sum += I.X + 2; @@ -791,7 +791,7 @@ void constness() { Sum += (*Pconstv)[I].X + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (const auto & I : *Pconstv) + // CHECK-FIXES: for (const auto & I : *Pconstv) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I.X); // CHECK-FIXES-NEXT: Sum += I.X + 2; } @@ -804,14 +804,14 @@ void constRef(const dependent& ConstVRef) { sum += ConstVRef[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : ConstVRef) + // CHECK-FIXES: for (int I : ConstVRef) { // CHECK-FIXES-NEXT: sum += I; for (auto I = ConstVRef.begin(), E = ConstVRef.end(); I != E; ++I) { sum += *I; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : ConstVRef) + // CHECK-FIXES: for (int I : ConstVRef) { // CHECK-FIXES-NEXT: sum += I; } @@ -889,7 +889,7 @@ void derefByValueTest() { printf("%d\n", DBV[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (unsigned int I : DBV) + // CHECK-FIXES: for (unsigned int I : DBV) { // CHECK-FIXES-NEXT: printf("%d\n", I); for (unsigned I = 0, E = DBV.size(); I < E; ++I) { @@ -897,7 +897,7 @@ void derefByValueTest() { printf("%d\n", DBV[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (unsigned int I : DBV) + // CHECK-FIXES: for (unsigned int I : DBV) { // CHECK-FIXES-NEXT: auto f = [DBV, &I]() {}; // CHECK-FIXES-NEXT: printf("%d\n", I); } @@ -960,7 +960,7 @@ template void _dependenceArrayTest() { for (unsigned j = 0; j < 3; ++j) printf("%d", test[j][i]); // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: use range-based for loop instead - // CHECK-FIXES: (auto & j : test) + // CHECK-FIXES: for (auto & j : test) // CHECK-FIXES: printf("%d", j[i]); } void dependenceArrayTest() { @@ -992,13 +992,13 @@ void test() { auto V = [T = Arr[I]]() {}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: auto V = [T = I]() {}; for (int I = 0; I < N; ++I) { auto V = [T = 10 + Arr[I]]() {}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: auto V = [T = 10 + I]() {}; for (int I = 0; I < N; ++I) { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-const.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-const.cpp index 6091f0a6552e3..59f472cfe0f10 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-const.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-const.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-loop-convert %t +// RUN: %check_clang_tidy %s modernize-loop-convert %t struct Str { Str() = default; @@ -43,7 +43,7 @@ void memberFunctionsAndOperators() { Array[I].constMember(0); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert] - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: I.constMember(0); for (int I = 0; I < N; ++I) { @@ -51,14 +51,14 @@ void memberFunctionsAndOperators() { foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: if (I < OtherStr) for (int I = 0; I < N; ++I) { if (Right[I] < OtherRight) foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (const auto & I : Right) + // CHECK-FIXES: for (const auto & I : Right) { // CHECK-FIXES-NEXT: if (I < OtherRight) // Calling non-const member functions is not. @@ -66,21 +66,21 @@ void memberFunctionsAndOperators() { Array[I].nonConstMember(0); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Array) + // CHECK-FIXES: for (auto & I : Array) { // CHECK-FIXES-NEXT: I.nonConstMember(0); for (int I = 0; I < N; ++I) { Array[I] = OtherStr; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Array) + // CHECK-FIXES: for (auto & I : Array) { // CHECK-FIXES-NEXT: I = OtherStr; for (int I = 0; I < N; ++I) { Right[I] = OtherRight; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Right) + // CHECK-FIXES: for (auto & I : Right) { // CHECK-FIXES-NEXT: I = OtherRight; } @@ -90,14 +90,14 @@ void usedAsParameterToFunctionOrOperator() { copyArg(Array[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: copyArg(I); for (int I = 0; I < N; ++I) { copyArg(Right[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Right) + // CHECK-FIXES: for (auto & I : Right) { // CHECK-FIXES-NEXT: copyArg(I); // Using as a const reference argument is allowed. @@ -105,7 +105,7 @@ void usedAsParameterToFunctionOrOperator() { constRefArg(Array[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: constRefArg(I); for (int I = 0; I < N; ++I) { @@ -113,14 +113,14 @@ void usedAsParameterToFunctionOrOperator() { foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: if (OtherStr < I) for (int I = 0; I < N; ++I) { constRefArg(Right[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (const auto & I : Right) + // CHECK-FIXES: for (const auto & I : Right) { // CHECK-FIXES-NEXT: constRefArg(I); // Using as a non-const reference is not. @@ -128,20 +128,20 @@ void usedAsParameterToFunctionOrOperator() { nonConstRefArg(Array[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Array) + // CHECK-FIXES: for (auto & I : Array) { // CHECK-FIXES-NEXT: nonConstRefArg(I); for (int I = 0; I < N; ++I) { nonConstRefArg(Right[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Right) + // CHECK-FIXES: for (auto & I : Right) { // CHECK-FIXES-NEXT: nonConstRefArg(I); for (int I = 0; I < N; ++I) { if (OtherRight < Right[I]) foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Right) + // CHECK-FIXES: for (auto & I : Right) { // CHECK-FIXES-NEXT: if (OtherRight < I) } @@ -151,19 +151,19 @@ void primitiveTypes() { copyArg(Ints[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: copyArg(Int); for (int I = 0; I < N; ++I) { constRefArg(Ints[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: constRefArg(Int); for (int I = 0; I < N; ++I) { nonConstRefArg(Ints[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & Int : Ints) + // CHECK-FIXES: for (int & Int : Ints) { // CHECK-FIXES-NEXT: nonConstRefArg(Int); // Builtin operators. @@ -173,7 +173,7 @@ void primitiveTypes() { foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: if (Int < N) for (int I = 0; I < N; ++I) { @@ -181,7 +181,7 @@ void primitiveTypes() { foo(); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: if (N == Int) // Assignment. @@ -189,21 +189,21 @@ void primitiveTypes() { Ints[I] = OtherInt; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & Int : Ints) + // CHECK-FIXES: for (int & Int : Ints) { // CHECK-FIXES-NEXT: Int = OtherInt; for (int I = 0; I < N; ++I) { OtherInt = Ints[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: OtherInt = Int; for (int I = 0; I < N; ++I) { OtherInt = Ints[I] = OtherInt; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & Int : Ints) + // CHECK-FIXES: for (int & Int : Ints) { // CHECK-FIXES-NEXT: OtherInt = Int = OtherInt; // Arithmetic operations. @@ -211,21 +211,21 @@ void primitiveTypes() { OtherInt += Ints[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: OtherInt += Int; for (int I = 0; I < N; ++I) { Ints[I] += Ints[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & Int : Ints) + // CHECK-FIXES: for (int & Int : Ints) { // CHECK-FIXES-NEXT: Int += Int; for (int I = 0; I < N; ++I) { int Res = 5 * (Ints[I] + 1) - Ints[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: int Res = 5 * (Int + 1) - Int; } @@ -238,7 +238,7 @@ void takingReferences() { Str &K = Array[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & I : Array) + // CHECK-FIXES: for (auto & I : Array) { // CHECK-FIXES-NEXT: Str &J = I; // CHECK-FIXES-NEXT: Str &K = I; for (int I = 0; I < N; ++I) { @@ -246,7 +246,7 @@ void takingReferences() { const Str &K = Array[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { // CHECK-FIXES-NEXT: const Str &J = I; // CHECK-FIXES-NEXT: const Str &K = I; @@ -256,7 +256,7 @@ void takingReferences() { int &K = Ints[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & Int : Ints) + // CHECK-FIXES: for (int & Int : Ints) { // CHECK-FIXES-NEXT: int &J = Int; // CHECK-FIXES-NEXT: int &K = Int; for (int I = 0; I < N; ++I) { @@ -264,7 +264,7 @@ void takingReferences() { const int &K = Ints[I]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: const int &J = Int; // CHECK-FIXES-NEXT: const int &K = Int; @@ -274,27 +274,27 @@ void takingReferences() { (void)J; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto J : Array) + // CHECK-FIXES: for (auto J : Array) { for (int I = 0; I < N; ++I) { Str &J = Array[I]; (void)J; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto & J : Array) + // CHECK-FIXES: for (auto & J : Array) { for (int I = 0; I < N; ++I) { const int &J = Ints[I]; (void)J; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int J : Ints) + // CHECK-FIXES: for (int J : Ints) { for (int I = 0; I < N; ++I) { int &J = Ints[I]; (void)J; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int & J : Ints) + // CHECK-FIXES: for (int & J : Ints) { } template @@ -315,7 +315,7 @@ void testContainerOfConstIents() { OtherInt -= Ints[I]; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { vector Strs; for (int I = 0; I < Strs.size(); ++I) { @@ -323,7 +323,7 @@ void testContainerOfConstIents() { constRefArg(Strs[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop - // CHECK-FIXES: for (auto Str : Strs) + // CHECK-FIXES: for (auto Str : Strs) { } // When we are inside a const-qualified member functions, all the data members @@ -341,20 +341,20 @@ class TestInsideConstFunction { copyArg(Ints[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { for (int I = 0; I < N; ++I) { Array[I].constMember(0); constRefArg(Array[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop - // CHECK-FIXES: for (auto I : Array) + // CHECK-FIXES: for (auto I : Array) { for (int I = 0; I < V.size(); ++I) { if (V[I]) copyArg(V[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop - // CHECK-FIXES: for (int I : V) + // CHECK-FIXES: for (int I : V) { } }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-extra.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-extra.cpp index 1ac555f1da0e6..161427ca9ecb4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-extra.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-extra.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-loop-convert %t -- -- -I %S/Inputs/loop-convert +// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I %S/Inputs/loop-convert #include "structures.h" @@ -14,7 +14,7 @@ void f() { int B = Arr[I][A]; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Arr) + // CHECK-FIXES: for (auto & I : Arr) { // CHECK-FIXES-NEXT: int A = 0; // CHECK-FIXES-NEXT: int B = I[A]; @@ -51,7 +51,7 @@ void aliasing() { int Y = T.X; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & T : Arr) + // CHECK-FIXES: for (auto & T : Arr) { // CHECK-FIXES-NOT: Val &{{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: int Y = T.X; @@ -64,7 +64,7 @@ void aliasing() { int Z = Arr[I].X + T.X; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Arr) + // CHECK-FIXES: for (auto & I : Arr) { // CHECK-FIXES-NEXT: Val &T = I; // CHECK-FIXES-NEXT: int Y = T.X; // CHECK-FIXES-NEXT: int Z = I.X + T.X; @@ -75,7 +75,7 @@ void aliasing() { int Z = Arr[I].X + T.X; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Arr) + // CHECK-FIXES: for (auto & I : Arr) { // CHECK-FIXES-NEXT: Val T = I; // CHECK-FIXES-NEXT: int Y = T.X; // CHECK-FIXES-NEXT: int Z = I.X + T.X; @@ -88,7 +88,7 @@ void aliasing() { int Y = T.X; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & T : V) + // CHECK-FIXES: for (auto & T : V) { // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: int Y = T.X; @@ -99,7 +99,7 @@ void aliasing() { int Y = T.X; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & T : *Pv) + // CHECK-FIXES: for (auto & T : *Pv) { // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: int Y = T.X; @@ -108,7 +108,7 @@ void aliasing() { int Y = T.X; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Arr) + // CHECK-FIXES: for (auto & I : Arr) { // CHECK-FIXES-NEXT: Val &T = func(I); // CHECK-FIXES-NEXT: int Y = T.X; @@ -119,8 +119,8 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Alias : IntArr) - // CHECK-FIXES-NEXT: if (Alias) + // CHECK-FIXES: for (int Alias : IntArr) { + // CHECK-FIXES-NEXT: if (Alias) { for (unsigned I = 0; I < N; ++I) { while (int Alias = IntArr[I]) { @@ -128,8 +128,8 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Alias : IntArr) - // CHECK-FIXES-NEXT: while (Alias) + // CHECK-FIXES: for (int Alias : IntArr) { + // CHECK-FIXES-NEXT: while (Alias) { for (unsigned I = 0; I < N; ++I) { switch (int Alias = IntArr[I]) { @@ -138,8 +138,8 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Alias : IntArr) - // CHECK-FIXES-NEXT: switch (Alias) + // CHECK-FIXES: for (int Alias : IntArr) { + // CHECK-FIXES-NEXT: switch (Alias) { for (unsigned I = 0; I < N; ++I) { for (int Alias = IntArr[I]; Alias < N; ++Alias) { @@ -147,8 +147,8 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Alias : IntArr) - // CHECK-FIXES-NEXT: for (; Alias < N; ++Alias) + // CHECK-FIXES: for (int Alias : IntArr) { + // CHECK-FIXES-NEXT: for (; Alias < N; ++Alias) { for (unsigned I = 0; I < N; ++I) { for (unsigned J = 0; int Alias = IntArr[I]; ++J) { @@ -156,15 +156,15 @@ void aliasing() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Alias : IntArr) - // CHECK-FIXES-NEXT: for (unsigned J = 0; Alias; ++J) + // CHECK-FIXES: for (int Alias : IntArr) { + // CHECK-FIXES-NEXT: for (unsigned J = 0; Alias; ++J) { struct IntRef { IntRef(); IntRef(const int& i); operator int*(); }; for (int I = 0; I < N; ++I) { IntRef Int(IntArr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : IntArr) + // CHECK-FIXES: for (int I : IntArr) { // CHECK-FIXES-NEXT: IntRef Int(I); int *PtrArr[N]; @@ -173,7 +173,7 @@ void aliasing() { printf("%d\n", *P); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto P : PtrArr) + // CHECK-FIXES: for (auto P : PtrArr) { // CHECK-FIXES-NEXT: printf("%d\n", *P); IntRef Refs[N]; @@ -182,7 +182,7 @@ void aliasing() { printf("%d\n", *P); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Ref : Refs) + // CHECK-FIXES: for (auto & Ref : Refs) { // CHECK-FIXES-NEXT: int *P = Ref; // CHECK-FIXES-NEXT: printf("%d\n", *P); @@ -212,7 +212,7 @@ void refs_and_vals() { Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : S_const) + // CHECK-FIXES: for (auto Alias : S_const) { // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; @@ -223,7 +223,7 @@ void refs_and_vals() { Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Alias : Ss) + // CHECK-FIXES: for (auto Alias : Ss) { // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; @@ -234,7 +234,7 @@ void refs_and_vals() { Alias.X = 0; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Alias : Ss) + // CHECK-FIXES: for (auto & Alias : Ss) { // CHECK-FIXES-NOT: MutableVal &{{[a-z_]+}} = // CHECK-FIXES-NEXT: {} // CHECK-FIXES-NEXT: Alias.X = 0; @@ -246,7 +246,7 @@ void refs_and_vals() { unsigned Othersize = Other.size(); } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Dep) + // CHECK-FIXES: for (int & It : Dep) { // CHECK-FIXES-NEXT: printf("%d\n", It); // CHECK-FIXES-NEXT: const int& Idx = Other[0]; // CHECK-FIXES-NEXT: unsigned Othersize = Other.size(); @@ -255,7 +255,7 @@ void refs_and_vals() { Other.at(i); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & i : Other) + // CHECK-FIXES: for (int & i : Other) { // CHECK-FIXES: i; for (int I = 0, E = Dep.size(); I != E; ++I) { @@ -273,21 +273,21 @@ struct MemberNaming { printf("%d\n", Ints[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: printf("%d\n", Int); for (int I = 0; I < N; ++I) { printf("%d\n", Ints_[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int Int : Ints_) + // CHECK-FIXES: for (int Int : Ints_) { // CHECK-FIXES-NEXT: printf("%d\n", Int); for (int I = 0; I < DInts.size(); ++I) { printf("%d\n", DInts[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (int DInt : DInts) + // CHECK-FIXES: for (int DInt : DInts) { // CHECK-FIXES-NEXT: printf("%d\n", DInt); } @@ -298,14 +298,14 @@ void MemberNaming::outOfLine() { printf("%d\n", Ints[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Int : Ints) + // CHECK-FIXES: for (int Int : Ints) { // CHECK-FIXES-NEXT: printf("%d\n", Int); for (int I = 0; I < N; ++I) { printf("%d\n", Ints_[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Int : Ints_) + // CHECK-FIXES: for (int Int : Ints_) { // CHECK-FIXES-NEXT: printf("%d\n", Int); } @@ -334,7 +334,7 @@ void sameNames() { (void)Nums[I]; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Nums) + // CHECK-FIXES: for (int & I : Nums) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2 + Num; // CHECK-FIXES-NEXT: (void)I; @@ -346,7 +346,7 @@ void sameNames() { (void)Nums[I]; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Nums) + // CHECK-FIXES: for (int & I : Nums) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I); // CHECK-FIXES-NEXT: Sum += I + 2 + Num + Elem; // CHECK-FIXES-NEXT: (void)I; @@ -357,7 +357,7 @@ void oldIndexConflict() { printf("Num: %d\n", Nums[Num]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int Num : Nums) + // CHECK-FIXES: for (int Num : Nums) { // CHECK-FIXES-NEXT: printf("Num: %d\n", Num); S Things; @@ -365,7 +365,7 @@ void oldIndexConflict() { printf("Thing: %d %d\n", Thing->X, (*Thing).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Thing : Things) + // CHECK-FIXES: for (auto & Thing : Things) { // CHECK-FIXES-NEXT: printf("Thing: %d %d\n", Thing.X, Thing.X); } @@ -376,7 +376,7 @@ void macroConflict() { printf("Max of 3 and 5: %d\n", MAX(3, 5)); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : MAXs) + // CHECK-FIXES: for (auto & It : MAXs) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5)); @@ -385,7 +385,7 @@ void macroConflict() { printf("Max of 3 and 5: %d\n", MAX(3, 5)); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto It : MAXs) + // CHECK-FIXES: for (auto It : MAXs) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5)); @@ -396,8 +396,8 @@ void macroConflict() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : DEFs) - // CHECK-FIXES-NEXT: if (It == DEF) + // CHECK-FIXES: for (int & It : DEFs) { + // CHECK-FIXES-NEXT: if (It == DEF) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); } @@ -407,7 +407,7 @@ void keywordConflict() { *It = 5; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : ints) + // CHECK-FIXES: for (int & It : ints) { // CHECK-FIXES-NEXT: It = 5; U __FUNCTION__s; @@ -416,7 +416,7 @@ void keywordConflict() { int __FUNCTION__s_It = (*It).X + 2; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : __FUNCTION__s) + // CHECK-FIXES: for (auto & It : __FUNCTION__s) { // CHECK-FIXES-NEXT: int __FUNCTION__s_It = It.X + 2; } @@ -435,7 +435,7 @@ void typeConflict() { *It = sizeof(Val); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Vals) + // CHECK-FIXES: for (int & It : Vals) { // CHECK-FIXES-NEXT: It = sizeof(Val); typedef struct Val TD; @@ -454,7 +454,7 @@ void typeConflict() { (void) *It; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : TDs) + // CHECK-FIXES: for (auto & It : TDs) { // CHECK-FIXES-NEXT: TD V; // CHECK-FIXES-NEXT: V.X = 5; @@ -464,7 +464,7 @@ void typeConflict() { *It = sizeof(St); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Sts) + // CHECK-FIXES: for (int & It : Sts) { // CHECK-FIXES-NEXT: It = sizeof(St); } @@ -528,8 +528,8 @@ void f() { } // CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead // CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Arr) - // CHECK-FIXES-NEXT: for (auto & J : Arr) + // CHECK-FIXES: for (auto & I : Arr) { + // CHECK-FIXES-NEXT: for (auto & J : Arr) { // CHECK-FIXES-NEXT: int K = I.X + J.X; // CHECK-FIXES-NOT: int L = I.X + I.X; @@ -542,8 +542,8 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Nest) - // CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J) + // CHECK-FIXES: for (auto & I : Nest) { + // CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J) { // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X); // Note that the order of M and N are switched for this test. @@ -554,8 +554,8 @@ void f() { } // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[I]) - // CHECK-FIXES: for (int J = 0; J < M; ++J) - // CHECK-FIXES-NEXT: for (auto & I : Nest) + // CHECK-FIXES: for (int J = 0; J < M; ++J) { + // CHECK-FIXES-NEXT: for (auto & I : Nest) { // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X); // The inner loop is also convertible. @@ -566,8 +566,8 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : NestT) - // CHECK-FIXES-NEXT: for (T::iterator TI = I.begin(), TE = I.end(); TI != TE; ++TI) + // CHECK-FIXES: for (auto & I : NestT) { + // CHECK-FIXES-NEXT: for (T::iterator TI = I.begin(), TE = I.end(); TI != TE; ++TI) { // CHECK-FIXES-NEXT: printf("%d", *TI); // The inner loop is also convertible. @@ -578,8 +578,8 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto I : NestS) - // CHECK-FIXES-NEXT: for (S::const_iterator SI = I.begin(), SE = I.end(); SI != SE; ++SI) + // CHECK-FIXES: for (auto I : NestS) { + // CHECK-FIXES-NEXT: for (S::const_iterator SI = I.begin(), SE = I.end(); SI != SE; ++SI) { // CHECK-FIXES-NEXT: printf("%d", *SI); for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { @@ -590,7 +590,7 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Ss : NestS) + // CHECK-FIXES: for (auto Ss : NestS) { for (Nested::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { S &Ss = *I; @@ -600,7 +600,7 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Ss : NestS) + // CHECK-FIXES: for (auto & Ss : NestS) { Foo foo; for (Nested::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { @@ -611,7 +611,7 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto Ss : NestS) + // CHECK-FIXES: for (auto Ss : NestS) { for (Nested::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) { S &Ss = *I; @@ -621,7 +621,7 @@ void f() { } } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & Ss : NestS) + // CHECK-FIXES: for (auto & Ss : NestS) { } @@ -638,7 +638,7 @@ void complexContainer() { MutableVal J = *I; } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & I : Exes[Index].getS()) + // CHECK-FIXES: for (auto & I : Exes[Index].getS()) { // CHECK-FIXES-NEXT: MutableVal K = I; // CHECK-FIXES-NEXT: MutableVal J = I; } @@ -650,7 +650,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : Tt) + // CHECK-FIXES: for (int & It : Tt) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); T *Pt; @@ -658,7 +658,7 @@ void f() { printf("I found %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : *Pt) + // CHECK-FIXES: for (int & It : *Pt) { // CHECK-FIXES-NEXT: printf("I found %d\n", It); S Ss; @@ -666,7 +666,7 @@ void f() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); S *Ps; @@ -674,35 +674,35 @@ void f() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & P : *Ps) + // CHECK-FIXES: for (auto & P : *Ps) { // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X); for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { printf("s has value %d\n", It->X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { It->X = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.X = 3; for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { (*It).X = 3; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.X = 3; for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) { It->nonConstFun(4, 5); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Ss) + // CHECK-FIXES: for (auto & It : Ss) { // CHECK-FIXES-NEXT: It.nonConstFun(4, 5); U Uu; @@ -710,14 +710,14 @@ void f() { printf("s has value %d\n", It->X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Uu) + // CHECK-FIXES: for (auto & It : Uu) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : Uu) + // CHECK-FIXES: for (auto & It : Uu) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); U::iterator A; @@ -733,7 +733,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : V) + // CHECK-FIXES: for (int & It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); for (dependent::iterator It(V.begin()); @@ -741,7 +741,7 @@ void f() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & It : V) + // CHECK-FIXES: for (int & It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); doublyDependent intmap; @@ -750,7 +750,7 @@ void f() { printf("intmap[%d] = %d", It->first, It->second); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto & It : intmap) + // CHECK-FIXES: for (auto & It : intmap) { // CHECK-FIXES-NEXT: printf("intmap[%d] = %d", It.first, It.second); } @@ -765,7 +765,7 @@ void different_type() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto It : Ss) + // CHECK-FIXES: for (auto It : Ss) { // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X); S *Ps; @@ -773,7 +773,7 @@ void different_type() { printf("s has value %d\n", (*It).X); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (auto P : *Ps) + // CHECK-FIXES: for (auto P : *Ps) { // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X); dependent V; @@ -781,14 +781,14 @@ void different_type() { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int It : V) + // CHECK-FIXES: for (int It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); for (dependent::const_iterator It(V.begin()); It != V.end(); ++It) { printf("Fibonacci number is %d\n", *It); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int It : V) + // CHECK-FIXES: for (int It : V) { // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It); } @@ -808,7 +808,7 @@ void messing_with_macros() { printf("Value: %d\n", Arr[I]); } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: printf("Value: %d\n", I); for (int I = 0; I < N; ++I) { @@ -821,7 +821,7 @@ void messing_with_macros() { THREE_PARAM(Arr[I], Arr[I], Arr[I]); } // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & I : Arr) + // CHECK-FIXES: for (int & I : Arr) { // CHECK-FIXES-NEXT: TWO_PARAM(I, I); // CHECK-FIXES-NEXT: THREE_PARAM(I, I, I); } @@ -907,10 +907,11 @@ void capturesIndex() { F(Arr[I]); } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) - // CHECK-FIXES-NEXT: auto F = [Arr, &I](int k) - // CHECK-FIXES-NEXT: printf("%d\n", I + k); - // CHECK-FIXES: F(I); + // CHECK-FIXES: for (int I : Arr) { + // CHECK-FIXES-NEXT: auto F = [Arr, &I](int k) { + // CHECK-FIXES-NEXT: printf("%d\n", I + k); + // CHECK-FIXES-NEXT: }; + // CHECK-FIXES-NEXT: F(I); } void implicitCapture() { @@ -939,8 +940,8 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) - // CHECK-FIXES-NEXT: auto G3 = [&]() + // CHECK-FIXES: for (int I : Arr) { + // CHECK-FIXES-NEXT: auto G3 = [&]() { // CHECK-FIXES-NEXT: int R3 = I; // CHECK-FIXES-NEXT: int J3 = I + R3; @@ -950,8 +951,8 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) - // CHECK-FIXES-NEXT: auto G4 = [=]() + // CHECK-FIXES: for (int I : Arr) { + // CHECK-FIXES-NEXT: auto G4 = [=]() { // CHECK-FIXES-NEXT: int R4 = I + 5; // Alias by value. @@ -962,8 +963,8 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int R5 : Arr) - // CHECK-FIXES-NEXT: auto G5 = [&]() + // CHECK-FIXES: for (int R5 : Arr) { + // CHECK-FIXES-NEXT: auto G5 = [&]() { // CHECK-FIXES-NEXT: int J5 = 8 + R5; // Alias by reference. @@ -974,8 +975,8 @@ void implicitCapture() { }; } // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int & R6 : Arr) - // CHECK-FIXES-NEXT: auto G6 = [&]() + // CHECK-FIXES: for (int & R6 : Arr) { + // CHECK-FIXES-NEXT: auto G6 = [&]() { // CHECK-FIXES-NEXT: int J6 = -1 + R6; } @@ -1029,14 +1030,14 @@ void captureByValue() { auto C1 = [&Arr, I]() { if (Arr[I] == 1); }; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Arr) + // CHECK-FIXES: for (int I : Arr) { // CHECK-FIXES-NEXT: auto C1 = [&Arr, &I]() { if (I == 1); }; for (unsigned I = 0; I < Dep.size(); ++I) { auto C2 = [&Dep, I]() { if (Dep[I] == 2); }; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Dep) + // CHECK-FIXES: for (int I : Dep) { // CHECK-FIXES-NEXT: auto C2 = [&Dep, &I]() { if (I == 2); }; } @@ -1062,7 +1063,7 @@ void f() { E Ee{ { { g( { Array[I] } ) } } }; } // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for (int I : Array) + // CHECK-FIXES: for (int I : Array) { // CHECK-FIXES-NEXT: int A{ I }; // CHECK-FIXES-NEXT: int B{ g(I) }; // CHECK-FIXES-NEXT: int C{ g( { I } ) }; @@ -1079,7 +1080,7 @@ void bug28341() { if (value > 127) ; // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead - // CHECK-FIXES: for(unsigned char value : v) + // CHECK-FIXES: for(unsigned char value : v) { // CHECK-FIXES-NEXT: if (value > 127) } } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared.cpp index 65ece773b7c1f..686b998af44e9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-shared.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-make-shared %t -- -- -I %S/Inputs/smart-ptr +// RUN: %check_clang_tidy %s modernize-make-shared %t -- -- -I %S/Inputs/smart-ptr #include "shared_ptr.h" // CHECK-FIXES: #include @@ -226,7 +226,7 @@ void initialization(int T, Base b) { // CHECK-FIXES: std::shared_ptr PAggr = std::make_shared(APair{T, 1}); PAggr.reset(new APair{T, 1}); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_shared instead - // CHECK-FIXES: std::make_shared(APair{T, 1}); + // CHECK-FIXES: PAggr = std::make_shared(APair{T, 1}); // Test different kinds of initialization of the pointee, when the shared_ptr // is initialized with braces. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp index 13103c735276a..bcdf4fb4e3756 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++14-or-later %s modernize-make-unique %t -- -- -I %S/Inputs/smart-ptr +// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-make-unique %t -- -- -I %S/Inputs/smart-ptr #include "unique_ptr.h" #include "initializer_list.h" @@ -271,7 +271,7 @@ void initialization(int T, Base b) { // CHECK-FIXES: std::unique_ptr PAggr = std::make_unique(APair{T, 1}); PAggr.reset(new APair{T, 1}); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use std::make_unique instead - // CHECK-FIXES: std::make_unique(APair{T, 1}); + // CHECK-FIXES: PAggr = std::make_unique(APair{T, 1}); // Check aggregate init with intermediate temporaries. std::unique_ptr PAggrTemp = std::unique_ptr(new APair({T, 1})); @@ -480,7 +480,7 @@ void initialization(int T, Base b) { std::unique_ptr FI; FI.reset(new int[5]()); // value initialization. // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: - // CHECK-FIXES: FI = std::make_unique(5); + // CHECK-FIXES: FI = std::make_unique(5); // value initialization. // The check doesn't give warnings and fixes for cases where the original new // expression does default initialization. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp index ae270dcccd76d..9dc05b9676138 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-min-max-use-initializer-list %t +// RUN: %check_clang_tidy %s modernize-min-max-use-initializer-list %t // CHECK-FIXES: #include namespace utils { @@ -206,7 +206,7 @@ int min7 = std::min(1, std::min(2, 3, fless_than), fgreater_than); // CHECK-FIXES: int min7 = std::min(1, std::min(2, 3, fless_than), fgreater_than); int max8 = std::max(1, std::max(2, 3, fless_than), less_than); -// CHECK-FIXES: int max8 = std::max(1, std::max(2, 3, fless_than), less_than) +// CHECK-FIXES: int max8 = std::max(1, std::max(2, 3, fless_than), less_than); int min8 = std::min(1, std::min(2, 3, fless_than), less_than); // CHECK-FIXES: int min8 = std::min(1, std::min(2, 3, fless_than), less_than); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp index 7538862dd83f8..cc237f4efcd96 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-pass-by-value %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy %s modernize-pass-by-value %t -- -- -fno-delayed-template-parsing namespace { // POD types are trivially move constructible. @@ -92,7 +92,7 @@ struct H { using namespace ns_H; H::H(const HMovable &M) : M(M) {} // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: pass by value and use std::move -// CHECK-FIXES: H(HMovable M) : M(std::move(M)) {} +// CHECK-FIXES: H::H(HMovable M) : M(std::move(M)) {} // Try messing up with macros. #define MOVABLE_PARAM(Name) const Movable & Name diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp index 5856b8882574a..3a986650d8d3d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/raw-string-literal.cpp @@ -2,7 +2,7 @@ char const *const BackSlash("goink\\frob"); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: escaped string literal can be written as a raw string literal [modernize-raw-string-literal] -// CHECK-FIXES: {{^}}char const *const BackSlash(R"(goink\frob)");{{$}} +// CHECK-FIXES: char const *const BackSlash(R"(goink\frob)"); char const *const PlainLiteral("plain literal"); @@ -41,7 +41,7 @@ char const *const Us("goink\\\037"); char const *const HexNonPrintable("\\\x03"); char const *const Delete("\\\177"); char const *const MultibyteSnowman("\xE2\x98\x83"); -// CHECK-FIXES: {{^}}char const *const MultibyteSnowman("\xE2\x98\x83");{{$}} +// CHECK-FIXES: char const *const MultibyteSnowman("\xE2\x98\x83"); char const *const TrailingSpace("A line \\with space. \n"); char const *const TrailingNewLine("A single \\line.\n"); @@ -59,39 +59,39 @@ wchar_t const *const WideRawLiteral(LR"(foobie\\bletch)"); char const *const SingleQuote("goink\'frob"); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: {{.*}} can be written as a raw string literal -// CHECK-XFIXES: {{^}}char const *const SingleQuote(R"(goink'frob)");{{$}} +// CHECK-XFIXES: char const *const SingleQuote(R"(goink'frob)"); char const *const DoubleQuote("goink\"frob"); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const DoubleQuote(R"(goink"frob)");{{$}} +// CHECK-FIXES: char const *const DoubleQuote(R"(goink"frob)"); char const *const QuestionMark("goink\?frob"); // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const QuestionMark(R"(goink?frob)");{{$}} +// CHECK-FIXES: char const *const QuestionMark(R"(goink?frob)"); char const *const RegEx("goink\\(one|two\\)\\\\\\?.*\\nfrob"); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const RegEx(R"(goink\(one|two\)\\\?.*\nfrob)");{{$}} +// CHECK-FIXES: char const *const RegEx(R"(goink\(one|two\)\\\?.*\nfrob)"); char const *const Path("C:\\Program Files\\Vendor\\Application\\Application.exe"); // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const Path(R"(C:\Program Files\Vendor\Application\Application.exe)");{{$}} +// CHECK-FIXES: char const *const Path(R"(C:\Program Files\Vendor\Application\Application.exe)"); char const *const ContainsSentinel("who\\ops)\""); // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const ContainsSentinel(R"lit(who\ops)")lit");{{$}} +// CHECK-FIXES: char const *const ContainsSentinel(R"lit(who\ops)")lit"); char const *const ContainsDelim("whoops)\")lit\""); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const ContainsDelim(R"lit1(whoops)")lit")lit1");{{$}} +// CHECK-FIXES: char const *const ContainsDelim(R"lit1(whoops)")lit")lit1"); char const *const OctalPrintable("\100\\"); // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const OctalPrintable(R"(@\)");{{$}} +// CHECK-FIXES: char const *const OctalPrintable(R"(@\)"); char const *const HexPrintable("\x40\\"); // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}} +// CHECK-FIXES: char const *const HexPrintable(R"(@\)"); char const *const prettyFunction(__PRETTY_FUNCTION__); char const *const function(__FUNCTION__); @@ -111,23 +111,23 @@ template void fn(char const *const Arg) { char const *const Str("foo\\bar"); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal - // CHECK-FIXES: {{^}} char const *const Str(R"(foo\bar)");{{$}} + // CHECK-FIXES: char const *const Str(R"(foo\bar)"); } template <> void fn(char const *const Arg) { char const *const Str("foo\\bar"); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}} can be written as a raw string literal - // CHECK-FIXES: {{^}} char const *const Str(R"(foo\bar)");{{$}} + // CHECK-FIXES: char const *const Str(R"(foo\bar)"); } void callFn() { fn("foo\\bar"); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}} can be written as a raw string literal - // CHECK-FIXES: {{^}} fn(R"(foo\bar)");{{$}} + // CHECK-FIXES: fn(R"(foo\bar)"); fn("foo\\bar"); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} can be written as a raw string literal - // CHECK-FIXES: {{^}} fn(R"(foo\bar)");{{$}} + // CHECK-FIXES: fn(R"(foo\bar)"); } namespace std { @@ -140,5 +140,5 @@ namespace gh97243 { using namespace std::ud; auto UserDefinedLiteral = "foo\\bar"_abc; // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} can be written as a raw string literal -// CHECK-FIXES: {{^}}auto UserDefinedLiteral = R"(foo\bar)"_abc; +// CHECK-FIXES: auto UserDefinedLiteral = R"(foo\bar)"_abc; } // namespace gh97243 diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg-delayed.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg-delayed.cpp index dd887758819eb..4e05ada1d2992 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg-delayed.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg-delayed.cpp @@ -2,7 +2,7 @@ int foo(void) { // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [modernize-redundant-void-arg] -// CHECK-FIXES: {{^}}int foo() {{{$}} +// CHECK-FIXES: int foo() { return 0; } @@ -10,7 +10,7 @@ template struct MyFoo { int foo(void) { // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg] -// CHECK-FIXES: {{^}} int foo() {{{$}} +// CHECK-FIXES: int foo() { return 0; } }; @@ -22,7 +22,7 @@ struct MyBar { // This declaration isn't instantiated and won't be parsed 'delayed-template-parsing'. int foo(void) { // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant void argument list in function definition [modernize-redundant-void-arg] -// CHECK-FIXES: {{^}} int foo() {{{$}} +// CHECK-FIXES: int foo() { return 0; } }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp index f43a910ba022c..631149761e5e8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-redundant-void-arg %t +// RUN: %check_clang_tidy %s modernize-redundant-void-arg %t #define NULL 0 @@ -19,7 +19,7 @@ int j = 1; int foo(void) { // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [modernize-redundant-void-arg] -// CHECK-FIXES: {{^}}int foo() {{{$}} +// CHECK-FIXES: int foo() { return 0; } @@ -32,23 +32,23 @@ typedef void my_void; int (*returns_fn_void_int(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function declaration // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function declaration -// CHECK-FIXES: {{^}}int (*returns_fn_void_int())();{{$}} +// CHECK-FIXES: int (*returns_fn_void_int())(); typedef int (*returns_fn_void_int_t(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: {{.*}} in typedef // CHECK-MESSAGES: :[[@LINE-2]]:44: warning: {{.*}} in typedef -// CHECK-FIXES: {{^}}typedef int (*returns_fn_void_int_t())();{{$}} +// CHECK-FIXES: typedef int (*returns_fn_void_int_t())(); // Should work for type aliases as well as typedef. using returns_fn_void_int_t2 = int (*(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: {{.*}} in type alias // CHECK-MESSAGES: :[[@LINE-2]]:46: warning: {{.*}} in type alias -// CHECK-FIXES: {{^}}using returns_fn_void_int_t2 = int (*())();{{$}} +// CHECK-FIXES: using returns_fn_void_int_t2 = int (*())(); int (*returns_fn_void_int(void))(void) { // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function definition // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}int (*returns_fn_void_int())() {{{$}} +// CHECK-FIXES: int (*returns_fn_void_int())() { return nullptr; } @@ -58,25 +58,25 @@ void (*(*returns_fn_returns_fn_void_void(void))(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function declaration // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function declaration // CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function declaration -// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())();{{$}} +// CHECK-FIXES: void (*(*returns_fn_returns_fn_void_void())())(); typedef void (*(*returns_fn_returns_fn_void_void_t(void))(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:52: warning: {{.*}} in typedef // CHECK-MESSAGES: :[[@LINE-2]]:59: warning: {{.*}} in typedef // CHECK-MESSAGES: :[[@LINE-3]]:66: warning: {{.*}} in typedef -// CHECK-FIXES: {{^}}typedef void (*(*returns_fn_returns_fn_void_void_t())())();{{$}} +// CHECK-FIXES: typedef void (*(*returns_fn_returns_fn_void_void_t())())(); void (*(*returns_fn_returns_fn_void_void(void))(void))(void) { // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function definition // CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function definition // CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())() {{{$}} +// CHECK-FIXES: void (*(*returns_fn_returns_fn_void_void())())() { return nullptr; } void bar(void) { // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}void bar() {{{$}} +// CHECK-FIXES: void bar() { } void op_fn(int i) { @@ -103,13 +103,13 @@ class gronk { void (*f1)(void); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in field declaration - // CHECK-FIXES: {{^ }}void (*f1)();{{$}} + // CHECK-FIXES: void (*f1)(); void (*op)(int i); void (gronk::*p1)(void); // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in field declaration - // CHECK-FIXES: {{^ }}void (gronk::*p1)();{{$}} + // CHECK-FIXES: void (gronk::*p1)(); int (gronk::*p_mi); @@ -119,13 +119,13 @@ class gronk { // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in function declaration // CHECK-MESSAGES: :[[@LINE-2]]:51: warning: {{.*}} in function declaration // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: {{.*}} in function declaration - // CHECK-FIXES: {{^}} void (*(*returns_fn_returns_fn_void_void())())();{{$}} + // CHECK-FIXES: void (*(*returns_fn_returns_fn_void_void())())(); void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)(void))(void))(void); // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: {{.*}} in field declaration // CHECK-MESSAGES: :[[@LINE-2]]:65: warning: {{.*}} in field declaration // CHECK-MESSAGES: :[[@LINE-3]]:72: warning: {{.*}} in field declaration - // CHECK-FIXES: {{^}} void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)())())();{{$}} + // CHECK-FIXES: void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)())())(); }; int i; @@ -138,35 +138,35 @@ double *pd; void (*f1)(void); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration -// CHECK-FIXES: {{^}}void (*f1)();{{$}} +// CHECK-FIXES: void (*f1)(); void (*f2)(void) = nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2)() = nullptr;{{$}} +// CHECK-FIXES: void (*f2)() = nullptr; void (*f2b)(void)(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2b)()(nullptr);{{$}} +// CHECK-FIXES: void (*f2b)()(nullptr); void (*f2c)(void){nullptr}; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2c)(){nullptr};{{$}} +// CHECK-FIXES: void (*f2c)(){nullptr}; void (*f2d)(void) = NULL; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2d)() = NULL;{{$}} +// CHECK-FIXES: void (*f2d)() = NULL; void (*f2e)(void)(NULL); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2e)()(NULL);{{$}} +// CHECK-FIXES: void (*f2e)()(NULL); void (*f2f)(void){NULL}; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f2f)(){NULL};{{$}} +// CHECK-FIXES: void (*f2f)(){NULL}; void (*f3)(void) = bar; // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (*f3)() = bar;{{$}} +// CHECK-FIXES: void (*f3)() = bar; void (*o1)(int i); void (*o2)(int i) = nullptr; @@ -185,7 +185,7 @@ void (*fc)() = bar; typedef void (function_ptr)(void); // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: {{.*}} in typedef -// CHECK-FIXES: {{^}}typedef void (function_ptr)();{{$}} +// CHECK-FIXES: typedef void (function_ptr)(); // intentionally not LLVM style to check preservation of whitespace typedef void (function_ptr2) @@ -245,15 +245,15 @@ void void (gronk::*p1)(void); // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration -// CHECK-FIXES: {{^}}void (gronk::*p1)();{{$}} +// CHECK-FIXES: void (gronk::*p1)(); void (gronk::*p2)(void) = &gronk::foo; // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}} in variable declaration with initializer -// CHECK-FIXES: {{^}}void (gronk::*p2)() = &gronk::foo;{{$}} +// CHECK-FIXES: void (gronk::*p2)() = &gronk::foo; typedef void (gronk::*member_function_ptr)(void); // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in typedef -// CHECK-FIXES: {{^}}typedef void (gronk::*member_function_ptr)();{{$}} +// CHECK-FIXES: typedef void (gronk::*member_function_ptr)(); // intentionally not LLVM style to check preservation of whitespace typedef void (gronk::*member_function_ptr2) @@ -269,11 +269,11 @@ typedef void (gronk::*member_function_ptr2) void gronk::foo() { void (*f1)(void) = &::bar; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer - // CHECK-FIXES: {{^ }}void (*f1)() = &::bar;{{$}} + // CHECK-FIXES: void (*f1)() = &::bar; void (*f2)(void); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration - // CHECK-FIXES: {{^ }}void (*f2)();{{$}} + // CHECK-FIXES: void (*f2)(); // intentionally not LLVM style to check preservation of whitespace void (*f3) @@ -289,14 +289,14 @@ void gronk::foo() { void gronk::bar(void) { // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}void gronk::bar() {{{$}} +// CHECK-FIXES: void gronk::bar() { void (gronk::*p3)(void) = &gronk::foo; // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in variable declaration with initializer - // CHECK-FIXES: {{^ }}void (gronk::*p3)() = &gronk::foo;{{$}} + // CHECK-FIXES: void (gronk::*p3)() = &gronk::foo; void (gronk::*p4)(void); // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in variable declaration - // CHECK-FIXES: {{^ }}void (gronk::*p4)();{{$}} + // CHECK-FIXES: void (gronk::*p4)(); // intentionally not LLVM style to check preservation of whitespace void (gronk::*p5) @@ -325,14 +325,14 @@ void gronk::bar2 gronk::gronk(void) // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}gronk::gronk(){{$}} +// CHECK-FIXES: gronk::gronk() : f1(nullptr), p1(nullptr) { } gronk::~gronk(void) { // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}gronk::~gronk() {{{$}} +// CHECK-FIXES: gronk::~gronk() { } class nutter { @@ -342,21 +342,21 @@ class nutter { nutter::nutter(void) { // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in function definition -// CHECK-FIXES: {{^}}nutter::nutter() {{{$}} +// CHECK-FIXES: nutter::nutter() { void (*f3)(void) = static_cast(0); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer // CHECK-MESSAGES: :[[@LINE-2]]:43: warning: {{.*}} in named cast - // CHECK-FIXES: void (*f3)() = static_cast(0);{{$}} + // CHECK-FIXES: void (*f3)() = static_cast(0); void (*f4)(void) = (void (*)(void)) 0; // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: {{.*}} in cast expression - // CHECK-FIXES: void (*f4)() = (void (*)()) 0;{{$}} + // CHECK-FIXES: void (*f4)() = (void (*)()) 0; void (*f5)(void) = reinterpret_cast(0); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{.*}} in variable declaration with initializer // CHECK-MESSAGES: :[[@LINE-2]]:48: warning: {{.*}} in named cast - // CHECK-FIXES: void (*f5)() = reinterpret_cast(0);{{$}} + // CHECK-FIXES: void (*f5)() = reinterpret_cast(0); // intentionally not LLVM style to check preservation of whitespace void (*f6)(void) = static_cast void (*)(void) { return f1; }; // CHECK-MESSAGES: [[@LINE-1]]:27: warning: {{.*}} in lambda expression // CHECK-MESSAGES: [[@LINE-2]]:45: warning: {{.*}} in lambda expression - // CHECK-FIXES: {{^ }}auto void_returner = []() -> void (*)() { return f1; };{{$}} + // CHECK-FIXES: auto void_returner = []() -> void (*)() { return f1; }; } #define M(x) x @@ -452,22 +452,22 @@ struct DefinitionWithNoBody { #define BODY {} #define LAMBDA1 [](void){} // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] -// CHECK-FIXES: LAMBDA1 [](){} +// CHECK-FIXES: #define LAMBDA1 [](){} #define LAMBDA2 [](void)BODY // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] -// CHECK-FIXES: LAMBDA2 []()BODY +// CHECK-FIXES: #define LAMBDA2 []()BODY #define LAMBDA3(captures, args, body) captures args body #define WRAP(...) __VA_ARGS__ #define LAMBDA4 (void)LAMBDA3([],(void),BODY) // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] -// CHECK-FIXES: LAMBDA4 (void)LAMBDA3([],(),BODY) +// CHECK-FIXES: #define LAMBDA4 (void)LAMBDA3([],(),BODY) #define LAMBDA5 []() -> void (*)(void) {return BODY;} // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: redundant void argument list in lambda expression [modernize-redundant-void-arg] -// CHECK-FIXES: LAMBDA5 []() -> void (*)() {return BODY;} +// CHECK-FIXES: #define LAMBDA5 []() -> void (*)() {return BODY;} void lambda_expression_with_macro_test(){ (void)LAMBDA1; (void)LAMBDA2; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp index dea0857405e9d..2281c1acad94f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-auto-ptr.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-replace-auto-ptr %t -- -- -I %S/Inputs/replace-auto-ptr +// RUN: %check_clang_tidy %s modernize-replace-auto-ptr %t -- -- -I %S/Inputs/replace-auto-ptr // CHECK-FIXES: #include @@ -15,7 +15,7 @@ std::auto_ptr create_derived_ptr(); // Test function return values (declaration) std::auto_ptr f_5(); // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: auto_ptr is deprecated -// CHECK-FIXES: std::unique_ptr f_5() +// CHECK-FIXES: std::unique_ptr f_5(); // Test function parameters. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp index 45893c6a15d26..efd6fc99269f9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp @@ -33,8 +33,8 @@ class TestClass1 { DISALLOW_COPY_AND_ASSIGN(TestClass1); }; // CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro] -// CHECK-FIXES-DEFAULT: {{^}} TestClass1(const TestClass1 &) = delete;{{$}} -// CHECK-FIXES-DEFAULT-NEXT: {{^}} const TestClass1 &operator=(const TestClass1 &) = delete;{{$}} +// CHECK-FIXES-DEFAULT: TestClass1(const TestClass1 &) = delete; +// CHECK-FIXES-DEFAULT-NEXT: const TestClass1 &operator=(const TestClass1 &) = delete; #define MY_MACRO_NAME(TypeName) @@ -43,8 +43,8 @@ class TestClass2 { MY_MACRO_NAME(TestClass2); }; // CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro] -// CHECK-FIXES-DIFFERENT-NAME: {{^}} TestClass2(const TestClass2 &) = delete;{{$}} -// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}} const TestClass2 &operator=(const TestClass2 &) = delete;{{$}} +// CHECK-FIXES-DIFFERENT-NAME: TestClass2(const TestClass2 &) = delete; +// CHECK-FIXES-DIFFERENT-NAME-NEXT: const TestClass2 &operator=(const TestClass2 &) = delete; #define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \ TypeName(const TypeName &) = delete; \ @@ -58,8 +58,8 @@ class TestClass3 { DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3) }; // CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro] -// CHECK-FIXES-FINALIZE: {{^}} TestClass3(const TestClass3 &) = delete;{{$}} -// CHECK-FIXES-FINALIZE-NEXT: {{^}} const TestClass3 &operator=(const TestClass3 &) = delete;{{$}} +// CHECK-FIXES-FINALIZE: TestClass3(const TestClass3 &) = delete; +// CHECK-FIXES-FINALIZE-NEXT: const TestClass3 &operator=(const TestClass3 &) = delete; #define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B) diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast-remove-stars.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast-remove-stars.cpp index 5b620adb36ab2..59d6d23a1dc7e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast-remove-stars.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast-remove-stars.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-auto %t -- \ +// RUN: %check_clang_tidy %s modernize-use-auto %t -- \ // RUN: -config="{CheckOptions: {modernize-use-auto.RemoveStars: 'true' , modernize-use-auto.MinTypeNameLength: '0'}}" \ // RUN: -- -frtti @@ -108,7 +108,7 @@ typedef unsigned char xmlChar; do { \ xmlChar *s = (xmlChar *)(x); \ } while (false); -// CHECK-FIXES: xmlChar *s = (xmlChar *)(x); +// CHECK-FIXES: xmlChar *s = (xmlChar *)(x); {{\\}} void f_cstyle_cast() { auto *a = new A(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast.cpp index 3946b97abb256..7f687ab5dd70b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-cast.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-auto %t -- \ +// RUN: %check_clang_tidy %s modernize-use-auto %t -- \ // RUN: -config="{CheckOptions: {modernize-use-auto.MinTypeNameLength: '0'}}" \ // RUN: -- -I %S/Inputs/use-auto -frtti @@ -108,7 +108,7 @@ typedef unsigned char xmlChar; do { \ xmlChar *s = (xmlChar *)(x); \ } while (false); -// CHECK-FIXES: xmlChar *s = (xmlChar *)(x); +// CHECK-FIXES: xmlChar *s = (xmlChar *)(x); {{\\}} void f_cstyle_cast() { auto *a = new A(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-for-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-for-pointer.cpp index 1fd4189fb327e..2cb0208e1b5dc 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-for-pointer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-for-pointer.cpp @@ -1,20 +1,20 @@ -// RUN: %check_clang_tidy --match-partial-fixes -check-suffix=REMOVE %s modernize-use-auto %t -- \ +// RUN: %check_clang_tidy -check-suffix=REMOVE %s modernize-use-auto %t -- \ // RUN: -config="{CheckOptions: {modernize-use-auto.RemoveStars: 'true', modernize-use-auto.MinTypeNameLength: '0'}}" -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-auto %t -- \ +// RUN: %check_clang_tidy %s modernize-use-auto %t -- \ // RUN: -config="{CheckOptions: {modernize-use-auto.RemoveStars: 'false', modernize-use-auto.MinTypeNameLength: '0'}}" void pointerToFunction() { void (*(*(f1)))() = static_cast(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing - // CHECK-FIXES-REMOVE: auto f1 = - // CHECK-FIXES: auto *f1 = + // CHECK-FIXES-REMOVE: auto f1 = static_cast(nullptr); + // CHECK-FIXES: auto *f1 = static_cast(nullptr); } void pointerToArray() { int(*a1)[2] = new int[10][2]; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing - // CHECK-FIXES-REMOVE: auto a1 = - // CHECK-FIXES: auto *a1 = + // CHECK-FIXES-REMOVE: auto a1 = new int[10][2]; + // CHECK-FIXES: auto *a1 = new int[10][2]; } void memberFunctionPointer() { @@ -23,7 +23,7 @@ void memberFunctionPointer() { }; void(A::* a1)() = static_cast(nullptr); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing - // CHECK-FIXES-REMOVE: auto a1 = - // CHECK-FIXES: auto *a1 = + // CHECK-FIXES-REMOVE: auto a1 = static_cast(nullptr); + // CHECK-FIXES: auto *a1 = static_cast(nullptr); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-iterator.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-iterator.cpp index 02fb64676c52d..a928b331e4a2a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-iterator.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-iterator.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++11,c++14 %s modernize-use-auto %t -- -- -I %S/Inputs/use-auto +// RUN: %check_clang_tidy -std=c++11,c++14 %s modernize-use-auto %t -- -- -I %S/Inputs/use-auto // FIXME: Fix the checker to work in C++17 mode. #include "containers.h" @@ -277,18 +277,18 @@ void pointer_to_iterator() { void loop() { for (std::vector::iterator I = Vec.begin(); I != Vec.end(); ++I) { // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use auto when declaring iterators - // CHECK-FIXES: for (auto I = Vec.begin(); I != Vec.end(); ++I) + // CHECK-FIXES: for (auto I = Vec.begin(); I != Vec.end(); ++I) { } for (int_iterator I = Vec.begin(), E = Vec.end(); I != E; ++I) { // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use auto when declaring iterators - // CHECK-FIXES: for (auto I = Vec.begin(), E = Vec.end(); I != E; ++I) + // CHECK-FIXES: for (auto I = Vec.begin(), E = Vec.end(); I != E; ++I) { } std::vector::iterator> IterVec; for (std::vector::iterator I : IterVec) { // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use auto when declaring iterators - // CHECK-FIXES: for (auto I : IterVec) + // CHECK-FIXES: for (auto I : IterVec) { } } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp index 6cea26ee1a31c..e954cee996c33 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp @@ -1,7 +1,7 @@ -// RUN: %check_clang_tidy --match-partial-fixes -check-suffix=0-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti -// RUN: %check_clang_tidy --match-partial-fixes -check-suffix=0-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti -// RUN: %check_clang_tidy --match-partial-fixes -check-suffix=1-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti -// RUN: %check_clang_tidy --match-partial-fixes -check-suffix=1-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti +// RUN: %check_clang_tidy -check-suffix=0-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti +// RUN: %check_clang_tidy -check-suffix=0-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: false, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti +// RUN: %check_clang_tidy -check-suffix=1-0 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 0}}" -- -frtti +// RUN: %check_clang_tidy -check-suffix=1-8 %s modernize-use-auto %t -- -config="{CheckOptions: {modernize-use-auto.RemoveStars: true, modernize-use-auto.MinTypeNameLength: 8}}" -- -frtti template extern T foo(); template struct P { explicit P(T t) : t_(t) {} T t_;}; @@ -17,10 +17,10 @@ int bar() { // CHECK-FIXES-1-0: auto i = {{.*}} // CHECK-FIXES-1-8: long i = {{.*}} const long ci = static_cast(foo()); - // CHECK-FIXES-0-0: auto ci = {{.*}} - // CHECK-FIXES-0-8: long ci = {{.*}} - // CHECK-FIXES-1-0: auto ci = {{.*}} - // CHECK-FIXES-1-8: long ci = {{.*}} + // CHECK-FIXES-0-0: const auto ci = {{.*}} + // CHECK-FIXES-0-8: const long ci = {{.*}} + // CHECK-FIXES-1-0: const auto ci = {{.*}} + // CHECK-FIXES-1-8: const long ci = {{.*}} long *pi = static_cast(foo()); // CHECK-FIXES-0-0: auto *pi = {{.*}} // CHECK-FIXES-0-8: long *pi = {{.*}} diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-bool-literals.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-bool-literals.cpp index 30c10efabaef3..1acb3c3594b0d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-bool-literals.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-bool-literals.cpp @@ -5,43 +5,43 @@ bool IntToTrue = 1; // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals] -// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}} +// CHECK-FIXES: bool IntToTrue = true; bool IntToFalse(0); // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}} +// CHECK-FIXES: bool IntToFalse(false); bool LongLongToTrue{0x1LL}; // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}} +// CHECK-FIXES: bool LongLongToTrue{true}; bool ExplicitCStyleIntToFalse = (bool)0; // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool ExplicitCStyleIntToFalse = false;{{$}} +// CHECK-FIXES: bool ExplicitCStyleIntToFalse = false; bool ExplicitFunctionalIntToFalse = bool(0); // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool ExplicitFunctionalIntToFalse = false;{{$}} +// CHECK-FIXES: bool ExplicitFunctionalIntToFalse = false; bool ExplicitStaticIntToFalse = static_cast(0); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool ExplicitStaticIntToFalse = false;{{$}} +// CHECK-FIXES: bool ExplicitStaticIntToFalse = false; #define TRUE_MACRO 1 -// CHECK-FIXES: {{^}}#define TRUE_MACRO 1{{$}} +// CHECK-FIXES: #define TRUE_MACRO 1 bool MacroIntToTrue = TRUE_MACRO; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool MacroIntToTrue = TRUE_MACRO;{{$}} +// CHECK-FIXES: bool MacroIntToTrue = TRUE_MACRO; #define FALSE_MACRO bool(0) -// CHECK-FIXES: {{^}}#define FALSE_MACRO bool(0){{$}} +// CHECK-FIXES: #define FALSE_MACRO bool(0) bool TrueBool = true; // OK bool FalseBool = bool(FALSE_MACRO); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool FalseBool = bool(FALSE_MACRO);{{$}} +// CHECK-FIXES: bool FalseBool = bool(FALSE_MACRO); void boolFunction(bool bar) { @@ -52,58 +52,58 @@ char Character = 0; // OK unsigned long long LongInteger = 1; // OK #define MACRO_DEPENDENT_CAST(x) static_cast(x) -// CHECK-FIXES: {{^}}#define MACRO_DEPENDENT_CAST(x) static_cast(x){{$}} +// CHECK-FIXES: #define MACRO_DEPENDENT_CAST(x) static_cast(x) bool MacroDependentBool = MACRO_DEPENDENT_CAST(0); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);{{$}} +// CHECK-FIXES: bool MacroDependentBool = MACRO_DEPENDENT_CAST(0); bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO); // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: converting integer literal to bool -// CHECK-FIXES: {{^}}bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);{{$}} +// CHECK-FIXES: bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO); class FooClass { public: FooClass() : JustBool(0) {} // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}} + // CHECK-FIXES: FooClass() : JustBool(false) {} FooClass(int) : JustBool{0} {} // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}} + // CHECK-FIXES: FooClass(int) : JustBool{false} {} private: bool JustBool; bool BoolWithBraces{0}; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}} + // CHECK-FIXES: bool BoolWithBraces{false}; bool BoolFromInt = 0; // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}} + // CHECK-FIXES: bool BoolFromInt = false; bool SimpleBool = true; // OK }; template void templateFunction(type) { type TemplateType = 0; - // CHECK-FIXES: {{^ *}}type TemplateType = 0;{{$}} + // CHECK-FIXES: type TemplateType = 0; } template void valueDependentTemplateFunction() { bool Boolean = c; - // CHECK-FIXES: {{^ *}}bool Boolean = c;{{$}} + // CHECK-FIXES: bool Boolean = c; } template void anotherTemplateFunction(type) { bool JustBool = 0; // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}bool JustBool = false;{{$}} + // CHECK-FIXES: bool JustBool = false; } int main() { boolFunction(1); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}} + // CHECK-FIXES: boolFunction(true); boolFunction(false); @@ -117,7 +117,7 @@ int main() { IntToTrue = 1; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}} + // CHECK-FIXES: IntToTrue = true; } static int Value = 1; @@ -126,7 +126,7 @@ bool Function1() { bool Result = Value == 1 ? 1 : 0; // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: converting integer literal to bool // CHECK-MESSAGES: :[[@LINE-2]]:34: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}bool Result = Value == 1 ? true : false;{{$}} + // CHECK-FIXES: bool Result = Value == 1 ? true : false; return Result; } @@ -134,18 +134,18 @@ bool Function2() { return Value == 1 ? 1 : 0; // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}return Value == 1 ? true : false;{{$}} + // CHECK-FIXES: return Value == 1 ? true : false; } void foo() { bool Result; Result = Value == 1 ? true : 0; // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}Result = Value == 1 ? true : false;{{$}} + // CHECK-FIXES: Result = Value == 1 ? true : false; Result = Value == 1 ? false : bool(0); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}} + // CHECK-FIXES: Result = Value == 1 ? false : false; Result = Value == 1 ? (bool)0 : false; // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: converting integer literal to bool - // CHECK-FIXES: {{^ *}}Result = Value == 1 ? false : false;{{$}} + // CHECK-FIXES: Result = Value == 1 ? false : false; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp index c3b2c184364a7..b92e9093c97ee 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp @@ -19,4 +19,4 @@ template > void first_greatergreater_is_enable_if() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void first_greatergreater_is_enable_if() requires T::some_value {{{$}} +// CHECK-FIXES: void first_greatergreater_is_enable_if() requires T::some_value { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp index 90131c3d86920..ecae36165e05e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp @@ -33,28 +33,28 @@ typename std::enable_if::type basic() { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj basic() requires T::some_value {{{$}} +// CHECK-FIXES: Obj basic() requires T::some_value { template std::enable_if_t basic_t() { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj basic_t() requires T::some_value {{{$}} +// CHECK-FIXES: Obj basic_t() requires T::some_value { template auto basic_trailing() -> typename std::enable_if::type { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:26: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}auto basic_trailing() -> Obj requires T::some_value {{{$}} +// CHECK-FIXES: auto basic_trailing() -> Obj requires T::some_value { template typename std::enable_if::type existing_constraint() requires (T::another_value) { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}typename std::enable_if::type existing_constraint() requires (T::another_value) {{{$}} +// CHECK-FIXES: typename std::enable_if::type existing_constraint() requires (T::another_value) { template typename std::enable_if::type decl_without_def(); @@ -79,32 +79,32 @@ typename std::enable_if::type* pointer_of_enable_if() { return nullptr; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int* pointer_of_enable_if() requires T::some_value { template std::enable_if_t* pointer_of_enable_if_t() { return nullptr; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int* pointer_of_enable_if_t() requires T::some_value { template const std::enable_if_t* const_pointer_of_enable_if_t() { return nullptr; } // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}const int* const_pointer_of_enable_if_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: const int* const_pointer_of_enable_if_t() requires T::some_value { template std::enable_if_t const * const_pointer_of_enable_if_t2() { return nullptr; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int const * const_pointer_of_enable_if_t2() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int const * const_pointer_of_enable_if_t2() requires T::some_value { template @@ -112,34 +112,34 @@ std::enable_if_t& reference_of_enable_if_t() { static int x; return x; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int& reference_of_enable_if_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int& reference_of_enable_if_t() requires T::some_value { template const std::enable_if_t& const_reference_of_enable_if_t() { static int x; return x; } // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}const int& const_reference_of_enable_if_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: const int& const_reference_of_enable_if_t() requires T::some_value { template typename std::enable_if::type enable_if_default_void() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void enable_if_default_void() requires T::some_value {{{$}} +// CHECK-FIXES: void enable_if_default_void() requires T::some_value { template std::enable_if_t enable_if_t_default_void() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void enable_if_t_default_void() requires T::some_value {{{$}} +// CHECK-FIXES: void enable_if_t_default_void() requires T::some_value { template std::enable_if_t* enable_if_t_default_void_pointer() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void* enable_if_t_default_void_pointer() requires T::some_value {{{$}} +// CHECK-FIXES: void* enable_if_t_default_void_pointer() requires T::some_value { namespace using_namespace_std { @@ -149,25 +149,25 @@ template typename enable_if::type with_typename() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void with_typename() requires T::some_value {{{$}} +// CHECK-FIXES: void with_typename() requires T::some_value { template enable_if_t with_t() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void with_t() requires T::some_value {{{$}} +// CHECK-FIXES: void with_t() requires T::some_value { template typename enable_if::type with_typename_and_type() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}int with_typename_and_type() requires T::some_value {{{$}} +// CHECK-FIXES: int with_typename_and_type() requires T::some_value { template enable_if_t with_t_and_type() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}int with_t_and_type() requires T::some_value {{{$}} +// CHECK-FIXES: int with_t_and_type() requires T::some_value { } // namespace using_namespace_std @@ -213,43 +213,43 @@ template std::enable_if_t::value> type_trait_value() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void type_trait_value() requires Traits::value {{{$}} +// CHECK-FIXES: void type_trait_value() requires Traits::value { template std::enable_if_t::member()> type_trait_member_call() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void type_trait_member_call() requires (Traits::member()) {{{$}} +// CHECK-FIXES: void type_trait_member_call() requires (Traits::member()) { template std::enable_if_t::value> negate() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void negate() requires (!Traits::value) {{{$}} +// CHECK-FIXES: void negate() requires (!Traits::value) { template std::enable_if_t::value1 && Traits::value2> conjunction() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void conjunction() requires (Traits::value1 && Traits::value2) {{{$}} +// CHECK-FIXES: void conjunction() requires (Traits::value1 && Traits::value2) { template std::enable_if_t::value1 || Traits::value2> disjunction() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void disjunction() requires (Traits::value1 || Traits::value2) {{{$}} +// CHECK-FIXES: void disjunction() requires (Traits::value1 || Traits::value2) { template std::enable_if_t::value1 && !Traits::value2> conjunction_with_negate() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void conjunction_with_negate() requires (Traits::value1 && !Traits::value2) {{{$}} +// CHECK-FIXES: void conjunction_with_negate() requires (Traits::value1 && !Traits::value2) { template std::enable_if_t::value1 == (Traits::value2 + 5)> complex_operators() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void complex_operators() requires (Traits::value1 == (Traits::value2 + 5)) {{{$}} +// CHECK-FIXES: void complex_operators() requires (Traits::value1 == (Traits::value2 + 5)) { } // namespace primary_expression_tests @@ -263,14 +263,14 @@ constexpr typename std::enable_if::type constexpr_decl() { return 10; } // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}constexpr int constexpr_decl() requires T::some_value {{{$}} +// CHECK-FIXES: constexpr int constexpr_decl() requires T::some_value { template static inline constexpr typename std::enable_if::type static_inline_constexpr_decl() { return 10; } // CHECK-MESSAGES: :[[@LINE-3]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}static inline constexpr int static_inline_constexpr_decl() requires T::some_value {{{$}} +// CHECK-FIXES: static inline constexpr int static_inline_constexpr_decl() requires T::some_value { template static @@ -279,16 +279,16 @@ static_decl() { return 10; } // CHECK-MESSAGES: :[[@LINE-4]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}static{{$}} -// CHECK-FIXES-NEXT: {{^}}int{{$}} -// CHECK-FIXES-NEXT: {{^}}static_decl() requires T::some_value {{{$}} +// CHECK-FIXES: static +// CHECK-FIXES-NEXT: int +// CHECK-FIXES-NEXT: static_decl() requires T::some_value { template constexpr /* comment */ typename std::enable_if::type constexpr_comment_decl() { return 10; } // CHECK-MESSAGES: :[[@LINE-3]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}constexpr /* comment */ int constexpr_comment_decl() requires T::some_value {{{$}} +// CHECK-FIXES: constexpr /* comment */ int constexpr_comment_decl() requires T::some_value { //////////////////////////////// @@ -302,45 +302,45 @@ struct AClass { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:10: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} static Obj static_method() requires T::some_value {{{$}} + // CHECK-FIXES: static Obj static_method() requires T::some_value { template typename std::enable_if::type member() { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} Obj member() requires T::some_value {{{$}} + // CHECK-FIXES: Obj member() requires T::some_value { template typename std::enable_if::type const_qualifier() const { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} Obj const_qualifier() const requires T::some_value {{{$}} + // CHECK-FIXES: Obj const_qualifier() const requires T::some_value { template typename std::enable_if::type rvalue_ref_qualifier() && { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} Obj rvalue_ref_qualifier() && requires T::some_value {{{$}} + // CHECK-FIXES: Obj rvalue_ref_qualifier() && requires T::some_value { template typename std::enable_if::type rvalue_ref_qualifier_comment() /* c1 */ && /* c2 */ { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} Obj rvalue_ref_qualifier_comment() /* c1 */ && /* c2 */ requires T::some_value {{{$}} + // CHECK-FIXES: Obj rvalue_ref_qualifier_comment() /* c1 */ && /* c2 */ requires T::some_value { template std::enable_if_t operator=(T&&) = delete; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} AClass& operator=(T&&) requires T::some_value = delete; + // CHECK-FIXES: AClass& operator=(T&&) requires T::some_value = delete; template std::enable_if_t operator=(ConsumeVariadic) noexcept(requires (T t) { t = 4; }) = delete; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} AClass& operator=(ConsumeVariadic) noexcept(requires (T t) { t = 4; }) requires T::some_value = delete; + // CHECK-FIXES: AClass& operator=(ConsumeVariadic) noexcept(requires (T t) { t = 4; }) requires T::some_value = delete; }; @@ -354,7 +354,7 @@ typename std::enable_if::type leading_comment() return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj leading_comment() requires /* check1 */ T::some_value {{{$}} +// CHECK-FIXES: Obj leading_comment() requires /* check1 */ T::some_value { template typename std::enable_if::type body_on_next_line() @@ -362,22 +362,22 @@ typename std::enable_if::type body_on_next_line() return Obj{}; } // CHECK-MESSAGES: :[[@LINE-4]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj body_on_next_line(){{$}} -// CHECK-FIXES-NEXT: {{^}}requires T::some_value {{{$}} +// CHECK-FIXES: Obj body_on_next_line() +// CHECK-FIXES-NEXT: requires T::some_value { template typename std::enable_if< /* check1 */ T::some_value, Obj>::type leading_comment_whitespace() { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj leading_comment_whitespace() requires /* check1 */ T::some_value {{{$}} +// CHECK-FIXES: Obj leading_comment_whitespace() requires /* check1 */ T::some_value { template typename std::enable_if::type leading_and_trailing_comment() { return Obj{}; } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}Obj leading_and_trailing_comment() requires /* check1 */ T::some_value /* check2 */ {{{$}} +// CHECK-FIXES: Obj leading_and_trailing_comment() requires /* check1 */ T::some_value /* check2 */ { template typename std::enable_if typename std::enable_if :: type* pointer_of_enable_if_t_with_spaces() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if_t_with_spaces() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int* pointer_of_enable_if_t_with_spaces() requires T::some_value { template typename std::enable_if :: /*c*/ type* pointer_of_enable_if_t_with_comment() { } // CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if_t_with_comment() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: int* pointer_of_enable_if_t_with_comment() requires T::some_value { template std::enable_if_t trailing_slash_slash_comment() { } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void trailing_slash_slash_comment() requires T::some_value // comment{{$}} -// CHECK-FIXES-NEXT: {{^}} {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void trailing_slash_slash_comment() requires T::some_value // comment +// CHECK-FIXES-NEXT: { } // namespace enable_if_in_return_type @@ -424,22 +424,22 @@ template ::type = 0> void basic() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void basic() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void basic() requires T::some_value { template = 0> void basic_t() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void basic_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void basic_t() requires T::some_value { template class U, class V, std::enable_if_t = 0> void basic_many_template_params() { } // CHECK-MESSAGES: :[[@LINE-3]]:61: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template class U, class V>{{$}} -// CHECK-FIXES-NEXT: {{^}}void basic_many_template_params() requires T::some_value {{{$}} +// CHECK-FIXES: template class U, class V> +// CHECK-FIXES-NEXT: void basic_many_template_params() requires T::some_value { template = 0> void no_dependent_type() { @@ -457,38 +457,37 @@ struct AClass : ABaseClass { void no_other_template_params() { } // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} {{$}} - // CHECK-FIXES-NEXT: {{^}} void no_other_template_params() requires T::some_value {{{$}} + // CHECK-FIXES: void no_other_template_params() requires T::some_value { template = 0> AClass() {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass() requires U::some_value {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass() requires U::some_value {} template = 0> AClass(int) : data(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int) requires U::some_value : data(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int) requires U::some_value : data(0) {} template = 0> AClass(int, int) : AClass(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int, int) requires U::some_value : AClass(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int, int) requires U::some_value : AClass(0) {} template = 0> AClass(int, int, int) : ABaseClass(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int, int, int) requires U::some_value : ABaseClass(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int, int, int) requires U::some_value : ABaseClass(0) {} template = 0> AClass(int, int, int, int) : data2(), data() {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int, int, int, int) requires U::some_value : data2(), data() {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int, int, int, int) requires U::some_value : data2(), data() {} int data; int data2; @@ -500,14 +499,14 @@ struct AClass2 : ABaseClass { template = 0> AClass2() {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass2() requires U::some_value {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass2() requires U::some_value {} template = 0> AClass2(int) : data2(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass2(int) requires U::some_value : data2(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass2(int) requires U::some_value : data2(0) {} int data = 10; int data2; @@ -518,16 +517,16 @@ template * = 0> void pointer_type() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void pointer_type() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void pointer_type() requires T::some_value { template * = nullptr> void param_on_newline() { } // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void param_on_newline() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void param_on_newline() requires T::some_value { template {{$}} -// CHECK-FIXES-NEXT: {{^}}void param_split_on_two_lines() requires ConsumeVariadic::value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void param_split_on_two_lines() requires ConsumeVariadic::value { template * = nullptr> void trailing_slash_slash_comment() { } // CHECK-MESSAGES: :[[@LINE-4]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void trailing_slash_slash_comment() requires T::some_value // comment{{$}} -// CHECK-FIXES-NEXT: {{^}} {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void trailing_slash_slash_comment() requires T::some_value // comment +// CHECK-FIXES-NEXT: { template * = nullptr, std::enable_if_t* = nullptr> void two_enable_ifs() { } // CHECK-MESSAGES: :[[@LINE-3]]:67: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template * = nullptr>{{$}} -// CHECK-FIXES-NEXT: {{^}}void two_enable_ifs() requires T::another_value {{{$}} +// CHECK-FIXES: template * = nullptr> +// CHECK-FIXES-NEXT: void two_enable_ifs() requires T::another_value { //////////////////////////////// // Negative tests @@ -584,16 +583,16 @@ void macro_entire_enable_if() { } // CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] // CHECK-MESSAGES: :[[@LINE-5]]:56: note: expanded from macro 'TEMPLATE_REQUIRES' -// CHECK-FIXES: {{^}}TEMPLATE_REQUIRES(U, U::some_value) -// CHECK-FIXES-NEXT: {{^}}void macro_entire_enable_if() {{{$}} +// CHECK-FIXES: TEMPLATE_REQUIRES(U, U::some_value) +// CHECK-FIXES-NEXT: void macro_entire_enable_if() { #define CONDITION U::some_value template = 0> void macro_condition() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void macro_condition() requires CONDITION {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void macro_condition() requires CONDITION { #undef CONDITION #define CONDITION !U::some_value @@ -601,8 +600,8 @@ template = 0> void macro_condition_not_primary() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void macro_condition_not_primary() requires (CONDITION) {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void macro_condition_not_primary() requires (CONDITION) { } // namespace enable_if_trailing_non_type_parameter @@ -617,22 +616,22 @@ template ::type> void basic() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void basic() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void basic() requires T::some_value { template > void basic_t() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void basic_t() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void basic_t() requires T::some_value { template class U, class V, typename = std::enable_if_t> void basic_many_template_params() { } // CHECK-MESSAGES: :[[@LINE-3]]:61: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template class U, class V>{{$}} -// CHECK-FIXES-NEXT: {{^}}void basic_many_template_params() requires T::some_value {{{$}} +// CHECK-FIXES: template class U, class V> +// CHECK-FIXES-NEXT: void basic_many_template_params() requires T::some_value { struct ABaseClass { ABaseClass(); @@ -645,32 +644,31 @@ struct AClass : ABaseClass { void no_other_template_params() { } // CHECK-MESSAGES: :[[@LINE-3]]:13: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} {{$}} - // CHECK-FIXES-NEXT: {{^}} void no_other_template_params() requires T::some_value {{{$}} + // CHECK-FIXES: void no_other_template_params() requires T::some_value { template > AClass() {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass() requires U::some_value {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass() requires U::some_value {} template > AClass(int) : data(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int) requires U::some_value : data(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int) requires U::some_value : data(0) {} template > AClass(int, int) : AClass(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int, int) requires U::some_value : AClass(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int, int) requires U::some_value : AClass(0) {} template > AClass(int, int, int) : ABaseClass(0) {} // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] - // CHECK-FIXES: {{^}} template {{$}} - // CHECK-FIXES-NEXT: {{^}} AClass(int, int, int) requires U::some_value : ABaseClass(0) {}{{$}} + // CHECK-FIXES: template + // CHECK-FIXES-NEXT: AClass(int, int, int) requires U::some_value : ABaseClass(0) {} int data; }; @@ -679,23 +677,23 @@ template *> void pointer_type() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void pointer_type() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void pointer_type() requires T::some_value { template &> void reference_type() { } // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void reference_type() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void reference_type() requires T::some_value { template *> void param_on_newline() { } // CHECK-MESSAGES: :[[@LINE-3]]:11: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}template {{$}} -// CHECK-FIXES-NEXT: {{^}}void param_on_newline() requires T::some_value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void param_on_newline() requires T::some_value { template {{$}} -// CHECK-FIXES-NEXT: {{^}}void param_split_on_two_lines() requires ConsumeVariadic::value {{{$}} +// CHECK-FIXES: template +// CHECK-FIXES-NEXT: void param_split_on_two_lines() requires ConsumeVariadic::value { //////////////////////////////// @@ -776,12 +774,12 @@ using enable_if_t = typename enable_if::type; template typename nonstd::enable_if::value, void>::type nonstd_enable_if() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void nonstd_enable_if() requires some_type_trait::value {}{{$}} +// CHECK-FIXES: void nonstd_enable_if() requires some_type_trait::value {} template nonstd::enable_if_t::value, void> nonstd_enable_if_t() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void nonstd_enable_if_t() requires some_type_trait::value {}{{$}} +// CHECK-FIXES: void nonstd_enable_if_t() requires some_type_trait::value {} template <> nonstd::enable_if_t::value, void> nonstd_enable_if_t() {} @@ -790,12 +788,12 @@ nonstd::enable_if_t::value, void> nonstd_enable_if_t() template typename nonstd::enable_if::value>::type nonstd_enable_if_one_param() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void nonstd_enable_if_one_param() requires some_type_trait::value {}{{$}} +// CHECK-FIXES: void nonstd_enable_if_one_param() requires some_type_trait::value {} template nonstd::enable_if_t::value> nonstd_enable_if_t_one_param() {} // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints] -// CHECK-FIXES: {{^}}void nonstd_enable_if_t_one_param() requires some_type_trait::value {}{{$}} +// CHECK-FIXES: void nonstd_enable_if_t_one_param() requires some_type_trait::value {} // No fix-its are offered for an enable_if with a different signature from the standard one. namespace boost { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp index cf0df449f6de5..5a868e2fbe04b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init-assignment.cpp @@ -197,32 +197,32 @@ class ArrayValueInit { ArrayValueInit() : m_array() {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayValueInit() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1] = {}; + // CHECK-FIXES: ArrayValueInit() {} + // CHECK-FIXES-NEXT: double m_array[1] = {}; }; class ArrayBraceInit { ArrayBraceInit() : m_array{} {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInit() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1] = {}; + // CHECK-FIXES: ArrayBraceInit() {} + // CHECK-FIXES-NEXT: double m_array[1] = {}; }; class ArrayBraceInitWithValue { ArrayBraceInitWithValue() : m_array{3.14} {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInitWithValue() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1] = {3.14}; + // CHECK-FIXES: ArrayBraceInitWithValue() {} + // CHECK-FIXES-NEXT: double m_array[1] = {3.14}; }; class ArrayBraceInitMultipleValues { ArrayBraceInitMultipleValues() : m_array{1.0, 2.0, 3.0} {} double m_array[3]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInitMultipleValues() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[3] = {1.0, 2.0, 3.0}; + // CHECK-FIXES: ArrayBraceInitMultipleValues() {} + // CHECK-FIXES-NEXT: double m_array[3] = {1.0, 2.0, 3.0}; }; } // namespace PR63285 diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp index 52b15dec37cd5..32735014ac119 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp @@ -479,8 +479,8 @@ struct EmptyBracedIntDefault { EmptyBracedIntDefault() : m_i{} {} int m_i; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm_i' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}EmptyBracedIntDefault() {} - // CHECK-FIXES-NEXT: {{^ }}int m_i{}; + // CHECK-FIXES: EmptyBracedIntDefault() {} + // CHECK-FIXES-NEXT: int m_i{}; }; namespace PR63285 { @@ -489,32 +489,32 @@ class ArrayValueInit { ArrayValueInit() : m_array() {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayValueInit() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{}; + // CHECK-FIXES: ArrayValueInit() {} + // CHECK-FIXES-NEXT: double m_array[1]{}; }; class ArrayBraceInit { ArrayBraceInit() : m_array{} {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInit() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{}; + // CHECK-FIXES: ArrayBraceInit() {} + // CHECK-FIXES-NEXT: double m_array[1]{}; }; class ArrayBraceInitWithValue { ArrayBraceInitWithValue() : m_array{3.14} {} double m_array[1]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInitWithValue() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[1]{3.14}; + // CHECK-FIXES: ArrayBraceInitWithValue() {} + // CHECK-FIXES-NEXT: double m_array[1]{3.14}; }; class ArrayBraceInitMultipleValues { ArrayBraceInitMultipleValues() : m_array{1.0, 2.0, 3.0} {} double m_array[3]; // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'm_array' [modernize-use-default-member-init] - // CHECK-FIXES: {{^ }}ArrayBraceInitMultipleValues() {} - // CHECK-FIXES-NEXT: {{^ }}double m_array[3]{1.0, 2.0, 3.0}; + // CHECK-FIXES: ArrayBraceInitMultipleValues() {} + // CHECK-FIXES-NEXT: double m_array[3]{1.0, 2.0, 3.0}; }; } // namespace PR63285 diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp index 6520620486942..3afa4a474f3ab 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default-copy.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-equals-default %t -- \ +// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- \ // RUN: -config="{CheckOptions: {modernize-use-equals-default.IgnoreMacros: false}}" \ // RUN: -- -fno-delayed-template-parsing -fexceptions -Wno-error=return-type @@ -35,7 +35,7 @@ struct IL { // Skip unions. union NU { NU(const NU &Other) : Field(Other.Field) {} - // CHECK-FIXES: NU(const NU &Other) : + // CHECK-FIXES: NU(const NU &Other) : Field(Other.Field) {} NU &operator=(const NU &Other) { Field = Other.Field; return *this; @@ -47,7 +47,7 @@ union NU { // Skip structs/classes containing anonymous unions. struct SU { SU(const SU &Other) : Field(Other.Field) {} - // CHECK-FIXES: SU(const SU &Other) : + // CHECK-FIXES: SU(const SU &Other) : Field(Other.Field) {} SU &operator=(const SU &Other) { Field = Other.Field; return *this; @@ -147,7 +147,7 @@ struct BF { BF(const BF &Other) : Field1(Other.Field1), Field2(Other.Field2), Field3(Other.Field3), Field4(Other.Field4) {}; // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use '= default' - // CHECK-FIXES: BF(const BF &Other) {{$}} + // CHECK-FIXES: BF(const BF &Other) // CHECK-FIXES: = default; BF &operator=(const BF &); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp index 209ca7d43664e..2eefdf9d6460c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-equals-default %t -- -- -fno-delayed-template-parsing -fexceptions +// RUN: %check_clang_tidy %s modernize-use-equals-default %t -- -- -fno-delayed-template-parsing -fexceptions // Out of line definition. class OL { @@ -127,7 +127,7 @@ Priv::Priv() {} struct SemiColon { SemiColon() {}; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: SemiColon() = default;{{$}} + // CHECK-FIXES: SemiColon() = default; }; struct SemiColonOutOfLine { @@ -136,16 +136,16 @@ struct SemiColonOutOfLine { SemiColonOutOfLine::SemiColonOutOfLine() {}; // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: use '= default' -// CHECK-FIXES: SemiColonOutOfLine::SemiColonOutOfLine() = default;{{$}} +// CHECK-FIXES: SemiColonOutOfLine::SemiColonOutOfLine() = default; // struct. struct ST { ST() {} // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: ST() = default;{{$}} + // CHECK-FIXES: ST() = default; ~ST() {} // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: ST() = default;{{$}} + // CHECK-FIXES: ~ST() = default; }; // Deleted constructor/destructor. @@ -238,13 +238,13 @@ struct DC : KW { DC() : KW() {} ~DC() override {} // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: ~DC() override = default;{{$}} + // CHECK-FIXES: ~DC() override = default; }; struct OverrideWithSemiColon : KW { ~OverrideWithSemiColon() override {}; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default' - // CHECK-FIXES: ~OverrideWithSemiColon() override = default;{{$}} + // CHECK-FIXES: ~OverrideWithSemiColon() override = default; }; struct Comments { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp index 135ee274433a2..1f26ff34a4d04 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++17 %s modernize-use-integer-sign-comparison %t -- \ +// RUN: %check_clang_tidy -std=c++17 %s modernize-use-integer-sign-comparison %t -- \ // RUN: -config="{CheckOptions: {modernize-use-integer-sign-comparison.EnableQtSupport: true}}" // CHECK-FIXES: #include @@ -92,7 +92,8 @@ int AllComparisons() { if (static_cast(uArray[2]) < static_cast(sArray[2])) return 0; // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison] -// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2])) +// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2]))) +// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one. if ((unsigned int)uArray[3] < (int)sArray[3]) return 0; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp index e0a84ef5aed26..628cee0bb0de7 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes -std=c++20 %s modernize-use-integer-sign-comparison %t +// RUN: %check_clang_tidy -std=c++20-or-later %s modernize-use-integer-sign-comparison %t // CHECK-FIXES: #include @@ -91,7 +91,8 @@ int AllComparisons() { if (static_cast(uArray[2]) < static_cast(sArray[2])) return 0; // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison] -// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2])) +// CHECK-FIXES: if (std::cmp_less(uArray[2],sArray[2]))) +// FIXME: There should only be 2 closing braces. The fix-it inserts an unbalanced one. if ((unsigned int)uArray[3] < (int)sArray[3]) return 0; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp index fe9d6de5f8f0f..27a96297c4119 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-nullptr %t -- \ +// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \ // RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL'}}" #define NULL 0 @@ -91,7 +91,7 @@ template struct pear { // it is often defined as __null and the check will catch it.) void f() { x = __null; } // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr [modernize-use-nullptr] - // CHECK-FIXES: x = nullptr; + // CHECK-FIXES: void f() { x = nullptr; } // But if you say 0, we allow the possibility that T can be used with integral // and pointer types, and "0" is an acceptable initializer (even if "{}" might @@ -118,11 +118,13 @@ void test_macro_args() { // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr // CHECK-FIXES: IS_EQ(static_cast(nullptr), Ptr); - IS_EQ(0, Ptr); // literal + // literal + IS_EQ(0, Ptr); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr // CHECK-FIXES: IS_EQ(nullptr, Ptr); - IS_EQ(NULL, Ptr); // macro + // macro + IS_EQ(NULL, Ptr); // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr // CHECK-FIXES: IS_EQ(nullptr, Ptr); @@ -205,7 +207,7 @@ void test_macro_args() { } a[2] = {ENTRY(0), {0}}; // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use nullptr // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: use nullptr - // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}}; + // CHECK-FIXES: } a[2] = {ENTRY(nullptr), {nullptr}}; #undef ENTRY #define assert1(expr) (expr) ? 0 : 1 diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-allow-override-and-final.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-allow-override-and-final.cpp index b6c3e0a70999a..8a6024c19abe9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-allow-override-and-final.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-allow-override-and-final.cpp @@ -17,24 +17,24 @@ struct Base { struct Simple : public Base { virtual ~Simple(); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} ~Simple() override; + // CHECK-FIXES: ~Simple() override; virtual void a() override; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'override' [modernize-use-override] - // CHECK-FIXES: {{^}} void a() override; + // CHECK-FIXES: void a() override; virtual void b() final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'final' [modernize-use-override] - // CHECK-FIXES: {{^}} void b() final; + // CHECK-FIXES: void b() final; virtual void c() final override; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'final' [modernize-use-override] - // CHECK-FIXES: {{^}} void c() final override; + // CHECK-FIXES: void c() final override; virtual void d() override final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'final' [modernize-use-override] - // CHECK-FIXES: {{^}} void d() override final; + // CHECK-FIXES: void d() override final; void e() final override; void f() override final; void g() final; void h() override; void i(); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this function with 'override' or (rarely) 'final' [modernize-use-override] - // CHECK-FIXES: {{^}} void i() override; + // CHECK-FIXES: void i() override; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-ms.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-ms.cpp index e7c00895860c2..a2720430b3935 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-ms.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-ms.cpp @@ -14,12 +14,12 @@ class EXPORT InheritedBase { class Derived : public Base { virtual EXPORT void a(); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} EXPORT void a() override; + // CHECK-FIXES: EXPORT void a() override; }; class EXPORT InheritedDerived : public InheritedBase { virtual void a(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} void a() override; + // CHECK-FIXES: void a() override; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-no-destructors.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-no-destructors.cpp index 2012d71c269a6..97e2220fe39e8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-no-destructors.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-no-destructors.cpp @@ -11,5 +11,5 @@ struct Simple : public Base { // CHECK-MESSAGES-NOT: warning: virtual void f(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void f() override; + // CHECK-FIXES: void f() override; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp index a06ada8964171..631f0d7cef45a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp @@ -43,5 +43,5 @@ struct Derived2 : BaseS, BaseU { // should warn, comes from non-template BaseU virtual void boo3(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^ }}void boo3() override; + // CHECK-FIXES: void boo3() override; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-macro.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-macro.cpp index f9ac6d462fa39..0e9a186aab900 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-macro.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-macro.cpp @@ -29,41 +29,41 @@ struct SimpleCases : public Base { public: virtual ~SimpleCases(); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'OVERRIDE' or (rarely) 'FINAL' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} ~SimpleCases() OVERRIDE; + // CHECK-FIXES: ~SimpleCases() OVERRIDE; void a(); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this function with 'OVERRIDE' or (rarely) 'FINAL' [modernize-use-override] - // CHECK-FIXES: {{^}} void a() OVERRIDE; + // CHECK-FIXES: void a() OVERRIDE; virtual void b(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'OVERRIDE' or (rarely) 'FINAL' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} void b() OVERRIDE; + // CHECK-FIXES: void b() OVERRIDE; virtual void c(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void c() OVERRIDE; + // CHECK-FIXES: void c() OVERRIDE; virtual void e() = 0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void e() OVERRIDE = 0; + // CHECK-FIXES: void e() OVERRIDE = 0; virtual void f2() const = 0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void f2() const OVERRIDE = 0; + // CHECK-FIXES: void f2() const OVERRIDE = 0; virtual void g() ABSTRACT; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void g() OVERRIDE ABSTRACT; + // CHECK-FIXES: void g() OVERRIDE ABSTRACT; virtual void j() const; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void j() const OVERRIDE; + // CHECK-FIXES: void j() const OVERRIDE; virtual void k() OVERRIDE; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'OVERRIDE' [modernize-use-override] - // CHECK-FIXES: {{^}} void k() OVERRIDE; + // CHECK-FIXES: void k() OVERRIDE; virtual void l() const OVERRIDE; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'OVERRIDE' [modernize-use-override] - // CHECK-FIXES: {{^}} void l() const OVERRIDE; + // CHECK-FIXES: void l() const OVERRIDE; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-no-macro-inscope.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-no-macro-inscope.cpp index 924dd536e6233..f348147e2cf04 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-no-macro-inscope.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-with-no-macro-inscope.cpp @@ -15,13 +15,13 @@ struct SimpleCases : public Base { public: virtual ~SimpleCases(); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} virtual ~SimpleCases(); + // CHECK-FIXES: virtual ~SimpleCases(); void a(); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this function with 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' [modernize-use-override] - // CHECK-FIXES: {{^}} void a(); + // CHECK-FIXES: void a(); virtual void b(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'CUSTOM_OVERRIDE' or (rarely) 'CUSTOM_FINAL' instead of 'virtual' [modernize-use-override] - // CHECK-FIXES: {{^}} virtual void b(); + // CHECK-FIXES: virtual void b(); }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp index c5745e39a324d..8e19fdd4a0a92 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy --match-partial-fixes %s modernize-use-override,cppcoreguidelines-explicit-virtual-functions %t -- -- -fexceptions +// RUN: %check_clang_tidy %s modernize-use-override,cppcoreguidelines-explicit-virtual-functions %t -- -- -fexceptions #define ABSTRACT = 0 @@ -54,182 +54,184 @@ struct SimpleCases : public Base { public: virtual ~SimpleCases(); // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' - // CHECK-FIXES: {{^}} ~SimpleCases() override; + // CHECK-FIXES: ~SimpleCases() override; void a(); // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this - // CHECK-FIXES: {{^}} void a() override; + // CHECK-FIXES: void a() override; void b() override; // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^}} void b() override; + // CHECK-FIXES: void b() override; virtual void c(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void c() override; + // CHECK-FIXES: void c() override; virtual void d() override; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'override' - // CHECK-FIXES: {{^}} void d() override; + // CHECK-FIXES: void d() override; virtual void d2() final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant since the function is already declared 'final' - // CHECK-FIXES: {{^}} void d2() final; + // CHECK-FIXES: void d2() final; virtual void e() = 0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void e() override = 0; + // CHECK-FIXES: void e() override = 0; virtual void f()=0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void f() override =0; + // CHECK-FIXES: void f() override =0; virtual void f2() const=0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void f2() const override =0; + // CHECK-FIXES: void f2() const override =0; virtual void g() ABSTRACT; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void g() override ABSTRACT; + // CHECK-FIXES: void g() override ABSTRACT; virtual void j() const; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void j() const override; + // CHECK-FIXES: void j() const override; - virtual MustUseResultObject k(); // Has an implicit attribute. + // Has an implicit attribute. + virtual MustUseResultObject k(); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using - // CHECK-FIXES: {{^}} MustUseResultObject k() override; + // CHECK-FIXES: MustUseResultObject k() override; virtual bool l() MUST_USE_RESULT UNUSED; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED; + // CHECK-FIXES: bool l() override MUST_USE_RESULT UNUSED; virtual bool n() UNUSED MUST_USE_RESULT; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} bool n() override UNUSED MUST_USE_RESULT; + // CHECK-FIXES: bool n() override UNUSED MUST_USE_RESULT; void m() override final; // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'override' is redundant since the function is already declared 'final' - // CHECK-FIXES: {{^}} void m() final; + // CHECK-FIXES: void m() final; virtual void m2() override final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' and 'override' are redundant since the function is already declared 'final' - // CHECK-FIXES: {{^}} void m2() final; + // CHECK-FIXES: void m2() final; virtual void o() __attribute__((unused)); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void o() override __attribute__((unused)); + // CHECK-FIXES: void o() override __attribute__((unused)); virtual void ne() noexcept(false); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void ne() noexcept(false) override; + // CHECK-FIXES: void ne() noexcept(false) override; virtual void t() throw(); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void t() throw() override; + // CHECK-FIXES: void t() throw() override; virtual /* */ void g2(); // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' - // CHECK-FIXES: {{^}} /* */ void g2() override; + // CHECK-FIXES: /* */ void g2() override; }; // CHECK-MESSAGES-NOT: warning: void SimpleCases::c() {} -// CHECK-FIXES: {{^}}void SimpleCases::c() {} +// CHECK-FIXES: void SimpleCases::c() {} SimpleCases::~SimpleCases() {} -// CHECK-FIXES: {{^}}SimpleCases::~SimpleCases() {} +// CHECK-FIXES: SimpleCases::~SimpleCases() {} struct DefaultedDestructor : public Base { DefaultedDestructor() {} virtual ~DefaultedDestructor() = default; // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using - // CHECK-FIXES: {{^}} ~DefaultedDestructor() override = default; + // CHECK-FIXES: ~DefaultedDestructor() override = default; }; struct FinalSpecified : public Base { public: virtual ~FinalSpecified() final; // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'virtual' is redundant since the function is already declared 'final' - // CHECK-FIXES: {{^}} ~FinalSpecified() final; + // CHECK-FIXES: ~FinalSpecified() final; void b() final; // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^}} void b() final; + // CHECK-FIXES: void b() final; virtual void d() final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} void d() final; + // CHECK-FIXES: void d() final; virtual void e() final = 0; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} void e() final = 0; + // CHECK-FIXES: void e() final = 0; virtual void j() const final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} void j() const final; + // CHECK-FIXES: void j() const final; virtual bool l() final MUST_USE_RESULT UNUSED; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} bool l() final MUST_USE_RESULT UNUSED; + // CHECK-FIXES: bool l() final MUST_USE_RESULT UNUSED; }; struct InlineDefinitions : public Base { public: virtual ~InlineDefinitions() {} // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using - // CHECK-FIXES: {{^}} ~InlineDefinitions() override {} + // CHECK-FIXES: ~InlineDefinitions() override {} void a() {} // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this - // CHECK-FIXES: {{^}} void a() override {} + // CHECK-FIXES: void a() override {} void b() override {} // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^}} void b() override {} + // CHECK-FIXES: void b() override {} virtual void c() {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void c() override + // CHECK-FIXES: void c() override virtual void d() override {} // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} void d() override {} + // CHECK-FIXES: void d() override {} virtual void j() const {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void j() const override + // CHECK-FIXES: void j() const override - virtual MustUseResultObject k(); // Has an implicit attribute. + // Has an implicit attribute. + virtual MustUseResultObject k(); // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using - // CHECK-FIXES: {{^}} MustUseResultObject k() override; + // CHECK-FIXES: MustUseResultObject k() override; virtual bool l() MUST_USE_RESULT UNUSED; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED; + // CHECK-FIXES: bool l() override MUST_USE_RESULT UNUSED; virtual void r() & {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void r() & override + // CHECK-FIXES: void r() & override virtual void rr() && {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void rr() && override + // CHECK-FIXES: void rr() && override virtual void cv() const volatile {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void cv() const volatile override + // CHECK-FIXES: void cv() const volatile override virtual void cv2() const volatile // some comment {} // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void cv2() const volatile override // some comment + // CHECK-FIXES: void cv2() const volatile override // some comment }; struct DefaultArguments : public Base { @@ -237,7 +239,7 @@ struct DefaultArguments : public Base { // Make sure the override fix is placed after the argument list. void il(IntPair p = {1, (2 + (3))}) {} // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this - // CHECK-FIXES: {{^}} void il(IntPair p = {1, (2 + (3))}) override {} + // CHECK-FIXES: void il(IntPair p = {1, (2 + (3))}) override {} }; struct Macros : public Base { @@ -245,31 +247,31 @@ struct Macros : public Base { // give up for now. NOT_VIRTUAL void a() NOT_OVERRIDE; // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: annotate this - // CHECK-FIXES: {{^}} NOT_VIRTUAL void a() override NOT_OVERRIDE; + // CHECK-FIXES: NOT_VIRTUAL void a() override NOT_OVERRIDE; VIRTUAL void b() NOT_OVERRIDE; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} VIRTUAL void b() override NOT_OVERRIDE; + // CHECK-FIXES: VIRTUAL void b() override NOT_OVERRIDE; NOT_VIRTUAL void c() OVERRIDE; // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^}} NOT_VIRTUAL void c() OVERRIDE; + // CHECK-FIXES: NOT_VIRTUAL void c() OVERRIDE; VIRTUAL void d() OVERRIDE; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant - // CHECK-FIXES: {{^}} VIRTUAL void d() OVERRIDE; + // CHECK-FIXES: VIRTUAL void d() OVERRIDE; #define FUNC(return_type, name) return_type name() FUNC(void, e); - // CHECK-FIXES: {{^}} FUNC(void, e); + // CHECK-FIXES: FUNC(void, e); #define F virtual void f(); F - // CHECK-FIXES: {{^}} F + // CHECK-FIXES: F VIRTUAL void g() OVERRIDE final; // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' and 'override' are redundant - // CHECK-FIXES: {{^}} VIRTUAL void g() final; + // CHECK-FIXES: VIRTUAL void g() final; }; // Tests for templates. @@ -280,7 +282,7 @@ template struct TemplateBase { template struct DerivedFromTemplate : public TemplateBase { virtual void f(T t); // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void f(T t) override; + // CHECK-FIXES: void f(T t) override; }; void f() { DerivedFromTemplate().f(2); } @@ -288,7 +290,7 @@ template struct UnusedMemberInstantiation : public C { virtual ~UnusedMemberInstantiation() {} // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: prefer using - // CHECK-FIXES: {{^}} ~UnusedMemberInstantiation() override {} + // CHECK-FIXES: ~UnusedMemberInstantiation() override {} }; struct IntantiateWithoutUse : public UnusedMemberInstantiation {}; @@ -303,7 +305,7 @@ template struct MembersOfSpecializations : public Base2 { void a() override; // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^}} void a() override; + // CHECK-FIXES: void a() override; }; template <> void MembersOfSpecializations<3>::a() {} void ff() { MembersOfSpecializations<3>().a(); }; @@ -313,11 +315,11 @@ void ff() { MembersOfSpecializations<3>().a(); }; struct TryStmtAsBody : public Base { void a() try // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this - // CHECK-FIXES: {{^}} void a() override try + // CHECK-FIXES: void a() override try { b(); } catch(...) { c(); } virtual void d() try // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using - // CHECK-FIXES: {{^}} void d() override try + // CHECK-FIXES: void d() override try { e(); } catch(...) { f(); } }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp index ea97d5b1fd467..6a6cb9857fff1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp @@ -1,11 +1,11 @@ -// RUN: %check_clang_tidy --match-partial-fixes \ -// RUN: -std=c++20 %s modernize-use-std-format %t -- \ +// RUN: %check_clang_tidy \ +// RUN: -std=c++20-or-later %s modernize-use-std-format %t -- \ // RUN: -config="{CheckOptions: {modernize-use-std-format.StrictMode: true}}" \ // RUN: -- -isystem %clang_tidy_headers \ // RUN: -DPRI_CMDLINE_MACRO="\"s\"" \ // RUN: -D__PRI_CMDLINE_MACRO="\"s\"" -// RUN: %check_clang_tidy --match-partial-fixes \ -// RUN: -std=c++20 %s modernize-use-std-format %t -- \ +// RUN: %check_clang_tidy \ +// RUN: -std=c++20-or-later %s modernize-use-std-format %t -- \ // RUN: -config="{CheckOptions: {modernize-use-std-format.StrictMode: false}}" \ // RUN: -- -isystem %clang_tidy_headers \ // RUN: -DPRI_CMDLINE_MACRO="\"s\"" \ @@ -70,32 +70,32 @@ std::string StrFormat_strict_conversion() { std::string StrFormat_field_width_and_precision() { auto s1 = absl::StrFormat("width only:%*d width and precision:%*.*f precision only:%.*f", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("width only:{:{}} width and precision:{:{}.{}f} precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5); + // CHECK-FIXES: auto s1 = std::format("width only:{:{}} width and precision:{:{}.{}f} precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5); auto s2 = absl::StrFormat("width and precision positional:%1$*2$.*3$f after", 3.14159265358979323846, 4, 2); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("width and precision positional:{0:{1}.{2}f} after", 3.14159265358979323846, 4, 2); + // CHECK-FIXES: auto s2 = std::format("width and precision positional:{0:{1}.{2}f} after", 3.14159265358979323846, 4, 2); const int width = 10, precision = 3; const unsigned int ui1 = 42, ui2 = 43, ui3 = 44; auto s3 = absl::StrFormat("casts width only:%*d width and precision:%*.*d precision only:%.*d\n", 3, ui1, 4, 2, ui2, 5, ui3); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES-NOTSTRICT: std::format("casts width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", ui1, 3, ui2, 4, 2, ui3, 5); - // CHECK-FIXES-STRICT: std::format("casts width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", static_cast(ui1), 3, static_cast(ui2), 4, 2, static_cast(ui3), 5); + // CHECK-FIXES-NOTSTRICT: auto s3 = std::format("casts width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", ui1, 3, ui2, 4, 2, ui3, 5); + // CHECK-FIXES-STRICT: auto s3 = std::format("casts width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", static_cast(ui1), 3, static_cast(ui2), 4, 2, static_cast(ui3), 5); auto s4 = absl::StrFormat("c_str removal width only:%*s width and precision:%*.*s precision only:%.*s", 3, s1.c_str(), 4, 2, s2.c_str(), 5, s3.c_str()); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("c_str removal width only:{:>{}} width and precision:{:>{}.{}} precision only:{:.{}}", s1, 3, s2, 4, 2, s3, 5); + // CHECK-FIXES: auto s4 = std::format("c_str removal width only:{:>{}} width and precision:{:>{}.{}} precision only:{:.{}}", s1, 3, s2, 4, 2, s3, 5); const std::string *ps1 = &s1, *ps2 = &s2, *ps3 = &s3; auto s5 = absl::StrFormat("c_str() removal pointer width only:%-*s width and precision:%-*.*s precision only:%-.*s", 3, ps1->c_str(), 4, 2, ps2->c_str(), 5, ps3->c_str()); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("c_str() removal pointer width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", *ps1, 3, *ps2, 4, 2, *ps3, 5); + // CHECK-FIXES: auto s5 = std::format("c_str() removal pointer width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", *ps1, 3, *ps2, 4, 2, *ps3, 5); iterator is1, is2, is3; auto s6 = absl::StrFormat("c_str() removal iterator width only:%-*s width and precision:%-*.*s precision only:%-.*s", 3, is1->c_str(), 4, 2, is2->c_str(), 5, is3->c_str()); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("c_str() removal iterator width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", *is1, 3, *is2, 4, 2, *is3, 5); + // CHECK-FIXES: auto s6 = std::format("c_str() removal iterator width only:{:{}} width and precision:{:{}.{}} precision only:{:.{}}", *is1, 3, *is2, 4, 2, *is3, 5); return s1 + s2 + s3 + s4 + s5 + s6; } @@ -105,7 +105,7 @@ void StrFormat_macros() { #define FORMAT absl::StrFormat auto s1 = FORMAT("Hello %d", 42); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("Hello {}", 42); + // CHECK-FIXES: auto s1 = std::format("Hello {}", 42); // Arguments that are macros aren't replaced with their value, even if they are rearranged. #define VALUE 3.14159265358979323846 @@ -113,7 +113,7 @@ void StrFormat_macros() { #define PRECISION 4 auto s3 = absl::StrFormat("Hello %*.*f", WIDTH, PRECISION, VALUE); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("Hello {:{}.{}f}", VALUE, WIDTH, PRECISION); + // CHECK-FIXES: auto s3 = std::format("Hello {:{}.{}f}", VALUE, WIDTH, PRECISION); const uint64_t u64 = 42; const uint32_t u32 = 32; @@ -121,11 +121,11 @@ void StrFormat_macros() { auto s4 = absl::StrFormat("Replaceable macro at end %" PRIu64, u64); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("Replaceable macro at end {}", u64); + // CHECK-FIXES: auto s4 = std::format("Replaceable macro at end {}", u64); auto s5 = absl::StrFormat("Replaceable macros in middle %" PRIu64 " %" PRIu32 "\n", u64, u32); // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format] - // CHECK-FIXES: std::format("Replaceable macros in middle {} {}\n", u64, u32); + // CHECK-FIXES: auto s5 = std::format("Replaceable macros in middle {} {}\n", u64, u32); // These need PRI and __PRI prefixes so that the check get as far as looking for // where the macro comes from. diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp index 9bf60e765312b..ec37f077df7fc 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp @@ -1,11 +1,11 @@ -// RUN: %check_clang_tidy --match-partial-fixes -check-suffixes=,STRICT \ -// RUN: -std=c++23 %s modernize-use-std-print %t -- \ +// RUN: %check_clang_tidy -check-suffixes=,STRICT \ +// RUN: -std=c++23-or-later %s modernize-use-std-print %t -- \ // RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: true}}" \ // RUN: -- -isystem %clang_tidy_headers -fexceptions \ // RUN: -DPRI_CMDLINE_MACRO="\"s\"" \ // RUN: -D__PRI_CMDLINE_MACRO="\"s\"" -// RUN: %check_clang_tidy --match-partial-fixes -check-suffixes=,NOTSTRICT \ -// RUN: -std=c++23 %s modernize-use-std-print %t -- \ +// RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT \ +// RUN: -std=c++23-or-later %s modernize-use-std-print %t -- \ // RUN: -config="{CheckOptions: {modernize-use-std-print.StrictMode: false}}" \ // RUN: -- -isystem %clang_tidy_headers -fexceptions \ // RUN: -DPRI_CMDLINE_MACRO="\"s\"" \ @@ -113,7 +113,7 @@ int printf_uses_return_value(int choice) { for (printf("for init statement %d\n", i);;) // CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'std::println' instead of 'printf' [modernize-use-std-print] - // CHECK-FIXES: std::println("for init statement {}", i); + // CHECK-FIXES: for (std::println("for init statement {}", i);;) ;; for (int j = printf("for init statement %d\n", i);;) @@ -124,7 +124,7 @@ int printf_uses_return_value(int choice) { for (;; printf("for expression %d\n", i)) // CHECK-MESSAGES: [[@LINE-1]]:11: warning: use 'std::println' instead of 'printf' [modernize-use-std-print] - // CHECK-FIXES: std::println("for expression {}", i) + // CHECK-FIXES: for (;; std::println("for expression {}", i)) ;; for (auto C : "foo") @@ -228,7 +228,7 @@ int fprintf_uses_return_value(int choice) { for (fprintf(stderr, "for init statement %d\n", i);;) // CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'std::println' instead of 'fprintf' [modernize-use-std-print] - // CHECK-FIXES: std::println(stderr, "for init statement {}", i); + // CHECK-FIXES: for (std::println(stderr, "for init statement {}", i);;) ;; for (int j = fprintf(stderr, "for init statement %d\n", i);;) @@ -239,7 +239,7 @@ int fprintf_uses_return_value(int choice) { for (;; fprintf(stderr, "for expression %d\n", i)) // CHECK-MESSAGES: [[@LINE-1]]:11: warning: use 'std::println' instead of 'fprintf' [modernize-use-std-print] - // CHECK-FIXES: std::println(stderr, "for expression {}", i) + // CHECK-FIXES: for (;; std::println(stderr, "for expression {}", i)) ;; for (auto C : "foo") diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp index 8a0618d154fd4..dd45094464d42 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp @@ -17,11 +17,11 @@ concept floating_point = std::is_same::value || std::is_same std::floating_point auto;{{$}} +// CHECK-FIXES: auto con1() -> std::floating_point auto; std::floating_point auto con1() { return 3.14f; } // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}auto con1() -> std::floating_point auto { return 3.14f; }{{$}} +// CHECK-FIXES: auto con1() -> std::floating_point auto { return 3.14f; } namespace a { template @@ -33,25 +33,25 @@ concept BinaryConcept = true; a::Concept decltype(auto) con2(); // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}auto con2() -> a::Concept decltype(auto);{{$}} +// CHECK-FIXES: auto con2() -> a::Concept decltype(auto); a::BinaryConcept decltype(auto) con3(); // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}auto con3() -> a::BinaryConcept decltype(auto);{{$}} +// CHECK-FIXES: auto con3() -> a::BinaryConcept decltype(auto); const std::floating_point auto* volatile con4(); // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}auto con4() -> const std::floating_point auto* volatile;{{$}} +// CHECK-FIXES: auto con4() -> const std::floating_point auto* volatile; template int req1(T t) requires std::floating_point; // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}auto req1(T t) -> int requires std::floating_point;{{$}} +// CHECK-FIXES: auto req1(T t) -> int requires std::floating_point; template T req2(T t) requires requires { t + t; }; // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a trailing return type for this function [modernize-use-trailing-return-type] - // CHECK-FIXES: {{^}}auto req2(T t) -> T requires requires { t + t; };{{$}} + // CHECK-FIXES: auto req2(T t) -> T requires requires { t + t; }; // // Operator c++20 defaulted comparison operators @@ -96,7 +96,7 @@ struct TestDefaultOperatorB { friend auto operator==(const TestDefaultOperatorB &, const TestDefaultOperatorB &) noexcept -> bool = default; friend bool operator<(const TestDefaultOperatorB &, const TestDefaultOperatorB &) noexcept = default; // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use a trailing return type for this function [modernize-use-trailing-return-type] - // CHECK-FIXES: {{^}} friend auto operator<(const TestDefaultOperatorB &, const TestDefaultOperatorB &) noexcept -> bool = default;{{$}} + // CHECK-FIXES: friend auto operator<(const TestDefaultOperatorB &, const TestDefaultOperatorB &) noexcept -> bool = default; }; namespace PR69863 { @@ -109,7 +109,7 @@ struct CustomCompileTimeString { template constexpr decltype(Str) operator""__csz() noexcept { // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use a trailing return type for this function [modernize-use-trailing-return-type] -// CHECK-FIXES: {{^}}constexpr auto operator""__csz() noexcept -> decltype(Str) { +// CHECK-FIXES: constexpr auto operator""__csz() noexcept -> decltype(Str) { return Str; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp index 33051c63e4f17..cd88c84629ce4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp @@ -10,15 +10,15 @@ namespace std { void test_lambda_positive() { auto l1 = [](auto x) { return x; }; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use a trailing return type for this lambda [modernize-use-trailing-return-type] - // CHECK-FIXES: {{^}} auto l1 = [](auto x) -> auto { return x; };{{$}} + // CHECK-FIXES: auto l1 = [](auto x) -> auto { return x; }; } template