@@ -4366,14 +4366,28 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
43664366 PrevDiag = diag::note_previous_builtin_declaration;
43674367 }
43684368
4369+ // Define a flag to determine whether merging MSVC compatible function
4370+ // declarations is necessary.
4371+ bool IsMergeRequiredForMSVC = false;
4372+
4373+ // Check if Microsoft extensions or MSVC compatibility mode are enabled.
4374+ if (getLangOpts().MicrosoftExt || getLangOpts().MSVCCompat)
4375+ IsMergeRequiredForMSVC = true;
4376+
4377+ // In _WIN32 environment, merging is always required.
43694378#ifdef _WIN32
4370- // Check and merge MSVC compatible function declarations.
4371- if (!MergeMSVCCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld)) {
4372- // Return false if the merge was successful.
4373- return false;
4374- }
4379+ IsMergeRequiredForMSVC = true;
43754380#endif
43764381
4382+ // Perform the merge if required.
4383+ if (IsMergeRequiredForMSVC) {
4384+ // Check and merge MSVC compatible function declarations.
4385+ if (!MergeMSVCCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld)) {
4386+ // Return false if the merge was successful.
4387+ return false;
4388+ }
4389+ }
4390+
43774391 Diag(New->getLocation(), diag::err_conflicting_types) << New->getDeclName();
43784392 Diag(OldLocation, PrevDiag) << Old << Old->getType();
43794393 llvm::errs() << "NewType: " << New->getType().getAsString() << "\n";
0 commit comments