Skip to content

[clang][AST] Assert that DependentNameType's Name and NNS are not null #122418

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

Conversation

HighCommander4
Copy link
Collaborator

Also clarify the comment above DependentNameType::getIdentifier()

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)

Changes

Also clarify the comment above DependentNameType::getIdentifier()


Full diff: https://github.com/llvm/llvm-project/pull/122418.diff

1 Files Affected:

  • (modified) clang/include/clang/AST/Type.h (+5-6)
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..2ec59c2cb9a8f6 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -7035,17 +7035,16 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
       : TypeWithKeyword(Keyword, DependentName, CanonType,
                         TypeDependence::DependentInstantiation |
                             toTypeDependence(NNS->getDependence())),
-        NNS(NNS), Name(Name) {}
+        NNS(NNS), Name(Name) {
+    assert(Name);
+  }
 
 public:
   /// Retrieve the qualification on this type.
   NestedNameSpecifier *getQualifier() const { return NNS; }
 
-  /// Retrieve the type named by the typename specifier as an identifier.
-  ///
-  /// This routine will return a non-NULL identifier pointer when the
-  /// form of the original typename was terminated by an identifier,
-  /// e.g., "typename T::type".
+  /// Retrieve the identifier that terminates this type name.
+  /// For example, "type" in "typename T::type".
   const IdentifierInfo *getIdentifier() const {
     return Name;
   }

@HighCommander4
Copy link
Collaborator Author

HighCommander4 commented Jan 10, 2025

Context: I was confused by the comment above DependentNameType::getIdentifier(), which suggested the function only sometimes returns non-null, but I couldn't find any case where it would return null.

It turns out the comment dates back to a time when the type stored a PointerUnion<const IdentifierInfo *, const TemplateSpecializationType *>, and only returned non-null if an IdentifierInfo * was stored. That was changed in c392f37.

Copy link
Contributor

@mizvekov mizvekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Indeed a DependentNameType with no 'Name' doesn't make sense.

Also clarify the comment above DependentNameType::getIdentifier()
@HighCommander4 HighCommander4 force-pushed the dependentnametype-assertion branch from a1e3dcc to 491b3ea Compare January 14, 2025 22:10
@HighCommander4 HighCommander4 changed the title [clang][AST] Assert that DependentNameType::Name is not null [clang][AST] Assert that DependentNameType's Name and NNS are not null Jan 14, 2025
@HighCommander4 HighCommander4 merged commit 9ac6a55 into llvm:main Jan 15, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants