[cfe-dev] clang-apply-replacements not de-duplicating replacements

Riyaz Puthiyapurayil via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 4 17:43:33 PST 2019


I have the following YAML file generated from clang-tidy (test-case at the end of the email). Notice that there are two identical replacements /u/riyaz/test.cc at offset:117. I am aware that clang-tidy does NOT de-duplicate replacements. But I thought clang-apply-replacements was supposed to do it. However, it adds the replacement text (override keyword) @offset:117 twice.

---
MainSourceFile:  /u/riyaz/test/test.cc
Diagnostics:
  - DiagnosticName:  modernize-use-override
    Message:         'prefer using ''override'' or (rarely) ''final'' instead of ''virtual'''
    FileOffset:      112
   FilePath:        /u/riyaz/test/test.cc
    Replacements:
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          99
        Length:          8
        ReplacementText: ''
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          117
        Length:          0
        ReplacementText: ' override'
  - DiagnosticName:  modernize-use-override
    Message:         'prefer using ''override'' or (rarely) ''final'' instead of ''virtual'''
    FileOffset:      112
    FilePath:        /u/riyaz/test/test.cc
    Replacements:
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          99
        Length:          8
        ReplacementText: ''
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          117
        Length:          0
        ReplacementText: ' override'
  - DiagnosticName:  modernize-use-override
    Message:         'prefer using ''override'' or (rarely) ''final'' instead of ''virtual'''
    FileOffset:      190
    FilePath:        /u/riyaz/test/test.cc
    Replacements:
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          177
        Length:          8
        ReplacementText: ''
      - FilePath:        /u/riyaz/test/test.cc
        Offset:          195
        Length:          0
        ReplacementText: ' override'
...

test.cc:

class C {
    public:
        virtual void foo() = 0;
};

class D : public C {
    public:
        virtual void foo() {}
};

#ifdef FOO
class E : public D {
    public:
        virtual void foo() {}
};
#endif

compile_commands.json:

[
  {
    "command": "clang++ -c /u/riyaz/test/test.cc",
    "directory": "/u/riyaz/test",
    "file": "test.cc"
  },
  {
    "command": "clang++ -DFOO -c /u/riyaz/test/test.cc",
    "directory": "/u/riyaz/test",
    "file": "test.cc"
  }
]

clang-tidy command line:

clang-tidy -export-fixes=test.cc.yaml -checks='-*,modernize-use-override' test.cc

test.cc after replacements (notice two override keywords @ D::foo)

class C {
    public:
        virtual void foo() = 0;
};

class D : public C {
    public:
        void foo() override override {}
};

#ifdef FOO
class E : public D {
    public:
        void foo() override {}
};
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190305/ab7222bf/attachment.html>


More information about the cfe-dev mailing list