-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang-doc] add namespace references to VarInfo #146964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesVarInfo was missing its addReference specialization. This causes errors Full diff: https://github.com/llvm/llvm-project/pull/146964.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 2cbf8bf6b2879..f756ae6d897c8 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -569,6 +569,17 @@ static llvm::Error addReference(T I, Reference &&R, FieldId F) {
"invalid type cannot contain Reference");
}
+template <> llvm::Error addReference(VarInfo *I, Reference &&R, FieldId F) {
+ switch (F) {
+ case FieldId::F_namespace:
+ I->Namespace.emplace_back(std::move(R));
+ return llvm::Error::success();
+ default:
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "VarInfo cannot contain this Reference");
+ }
+}
+
template <> llvm::Error addReference(TypeInfo *I, Reference &&R, FieldId F) {
switch (F) {
case FieldId::F_type:
diff --git a/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
new file mode 100644
index 0000000000000..5edfb34f34a13
--- /dev/null
+++ b/clang-tools-extra/test/clang-doc/json/nested-namespace.cpp
@@ -0,0 +1,36 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/nested/index.json --check-prefix=NESTED
+// RUN: FileCheck %s < %t/nested/inner/index.json --check-prefix=INNER
+
+namespace nested {
+ int Global;
+ namespace inner {
+ int InnerGlobal;
+ } // namespace inner
+} // namespace nested
+
+// NESTED: "Variables": [
+// NESTED-NEXT: {
+// NESTED-NEXT: "IsStatic": false,
+// NESTED-NEXT: "Location": {
+// NESTED-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
+// NESTED-NEXT: "LineNumber": 7
+// NESTED-NEXT: },
+// NESTED-NEXT: "Name": "Global",
+// NESTED-NEXT: "Namespace": [
+// NESTED-NEXT: "nested"
+// NESTED-NEXT: ],
+
+// INNER: "Variables": [
+// INNER-NEXT: {
+// INNER-NEXT: "IsStatic": false,
+// INNER-NEXT: "Location": {
+// INNER-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
+// INNER-NEXT: "LineNumber": 9
+// INNER-NEXT: },
+// INNER-NEXT: "Name": "InnerGlobal",
+// INNER-NEXT: "Namespace": [
+// INNER-NEXT: "inner",
+// INNER-NEXT: "nested"
+// INNER-NEXT: ],
\ No newline at end of file
|
petrhosek
reviewed
Jul 3, 2025
petrhosek
approved these changes
Jul 3, 2025
VarInfo was missing its addReference specialization. This causes errors when a VarInfo is inside a namespace that isn't the global namespace.
c686da5 to
f505202
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

VarInfo was missing its addReference specialization. This causes errors
when a VarInfo is inside a namespace that isn't the global namespace.