Просмотр исходного кода

Use `Decl::getAsFunction()` to cast `clang_decl` to `FunctionDecl` (#5737)

This seems like a better practice though has no effect since we don't
support templates yet.

Part of #5436.
Boaz Brickner 10 месяцев назад
Родитель
Сommit
b90d3b7751
2 измененных файлов с 3 добавлено и 4 удалено
  1. 1 2
      toolchain/check/import_cpp.cpp
  2. 2 2
      toolchain/lower/file_context.cpp

+ 1 - 2
toolchain/check/import_cpp.cpp

@@ -783,8 +783,7 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
 static auto ImportNameDecl(Context& context, SemIR::LocId loc_id,
                            SemIR::NameScopeId scope_id, SemIR::NameId name_id,
                            clang::NamedDecl* clang_decl) -> SemIR::InstId {
-  if (auto* clang_function_decl =
-          clang::dyn_cast<clang::FunctionDecl>(clang_decl)) {
+  if (auto* clang_function_decl = clang_decl->getAsFunction()) {
     return ImportFunctionDecl(context, loc_id, scope_id, name_id,
                               clang_function_decl);
   }

+ 2 - 2
toolchain/lower/file_context.cpp

@@ -445,8 +445,8 @@ auto FileContext::BuildFunctionDecl(SemIR::FunctionId function_id,
       clang_decl_id.has_value()) {
     CARBON_CHECK(!specific_id.has_value(),
                  "Specific functions cannot have C++ definitions");
-    HandleReferencedCppFunction(clang::dyn_cast<clang::FunctionDecl>(
-        sem_ir().clang_decls().Get(clang_decl_id).decl));
+    HandleReferencedCppFunction(
+        sem_ir().clang_decls().Get(clang_decl_id).decl->getAsFunction());
     // TODO: Check that the signature and mangling generated by Clang and the
     // one we generated are the same.
   }