]> granicus.if.org Git - clang/commitdiff
Add an assert to ParamCommandComment::getParamIndex() -- it should not be
authorDmitri Gribenko <gribozavr@gmail.com>
Mon, 30 Jul 2012 17:38:19 +0000 (17:38 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Mon, 30 Jul 2012 17:38:19 +0000 (17:38 +0000)
called unless index is valid.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160970 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Comment.h
tools/libclang/CXComment.cpp

index 55cb08141a9db64698e5814a13733e1a37873e4c..4c20618ca17f6efcc11e7e0fed7e0532e38a8a85 100644 (file)
@@ -713,6 +713,7 @@ public:
   }
 
   unsigned getParamIndex() const LLVM_READONLY {
+    assert(isParamIndexValid());
     return ParamIndex;
   }
 
index dfa782005b39e2e59f2ea243d4163ce89deaf135..4189b31446a379361caebd7d120736446616483e 100644 (file)
@@ -256,7 +256,7 @@ unsigned clang_ParamCommandComment_isParamIndexValid(CXComment CXC) {
 
 unsigned clang_ParamCommandComment_getParamIndex(CXComment CXC) {
   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
-  if (!PCC)
+  if (!PCC || !PCC->isParamIndexValid())
     return ParamCommandComment::InvalidParamIndex;
 
   return PCC->getParamIndex();
@@ -316,11 +316,18 @@ namespace {
 
 class ParamCommandCommentCompareIndex {
 public:
+  /// This comparison will sort parameters with valid index by index and
+  /// invalid (unresolved) parameters last.
   bool operator()(const ParamCommandComment *LHS,
                   const ParamCommandComment *RHS) const {
-    // To sort invalid (unresolved) parameters last, this comparison relies on
-    // invalid indices to be UINT_MAX.
-    return LHS->getParamIndex() < RHS->getParamIndex();
+    unsigned LHSIndex = UINT_MAX;
+    unsigned RHSIndex = UINT_MAX;
+    if (LHS->isParamIndexValid())
+      LHSIndex = LHS->getParamIndex();
+    if (RHS->isParamIndexValid())
+      RHSIndex = RHS->getParamIndex();
+
+    return LHSIndex < RHSIndex;
   }
 };