D18224: Clang Plugin: Report some problems from included files

Thomas Schöps noreply at phabricator.kde.org
Sun Jan 13 14:08:19 GMT 2019


thomassc created this revision.
Herald added a project: KDevelop.
Herald added a subscriber: kdevelop-devel.
thomassc requested review of this revision.

REVISION SUMMARY
  Consider the following piece of faulty code:
  
  struct A {};
  
  template <typename T>
  T AddObjects(const T& a, const T& b) {
  
    return a + b;
  
  }
  
  int main(int /*argc*/, char* /*argv*/[]) {
  
    A a, b;
    AddObjects(a, b);
    
    return 0;
  
  }
  
  This fails since struct A does not have an operator +. The actual error could be either in function AddObjects()
  (since it adds two objects that should not be added) or in the call to AddObjects (since it might be called
  with a type that it does not support). For the code above, KDevelop will however only report an error inside the template
  function. Now, consider that the template function is in an external library, and the fault is it being called with
  wrong arguments. This way, no error will be visible to the user at all, despite the error being within the user's code.
  This is for example commonly the case when using the "Eigen" linear algebra library and trying to add incompatible matrices.
  
  The diff proposed here creates ClangProblems for certain diagnostics that are located in included files, if there is
  a child diagnostic in the current file that ends on "requested here". This would error-highlight the call in the example
  above when the template function is in an external header.
  
  In addition, the existing code which creates ClangProblems already included missing-include errors in the error list of the parsed file with the intention
  to make them visible to the user. However, it seems that this was not actually the case, since the problem reporter plugin
  by default filters those errors out, since their finalLocation is in another file. Thus, the proposed diff also treats those
  errors in a similar way as the "requested here" errors to make them show up.
  
  Note 1: In case the template function and the call are located in the same file, KDevelop will still only report the error
  within the template function with this patch applied. Similarly, if there is a chain of multiple template functions within
  the same file that call each other and finally cause an error in an external template function, the "requested here" error
  highlight will only be generated for the first one and not for the others.
  
  Note 2: While testing, I noticed some inconsistencies in which errors are detected upon different actions: pressing F5 <https://phabricator.kde.org/F5>,
  modifying the source file, or modifying the header. Not sure what the cause for this is. Sometimes the errors in
  included files only seem to be reported for the include files themselves and not for the source files.

TEST PLAN
  Did short manual testing. Trying to add incompatible Eigen matrices is reported as an error now and underlined red.

REPOSITORY
  R32 KDevelop

BRANCH
  report_some_problems_from_other_files (branched from master)

REVISION DETAIL
  https://phabricator.kde.org/D18224

AFFECTED FILES
  plugins/clang/duchain/clangproblem.cpp
  plugins/clang/duchain/clangproblem.h
  plugins/clang/duchain/parsesession.cpp

To: thomassc
Cc: kdevelop-devel, glebaccon, hase, antismap, iodelay, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20190113/456ef142/attachment-0001.html>


More information about the KDevelop-devel mailing list