@@ -4366,14 +4366,28 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
4366
4366
PrevDiag = diag::note_previous_builtin_declaration;
4367
4367
}
4368
4368
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.
4369
4378
#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;
4375
4380
#endif
4376
4381
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
+
4377
4391
Diag(New->getLocation(), diag::err_conflicting_types) << New->getDeclName();
4378
4392
Diag(OldLocation, PrevDiag) << Old << Old->getType();
4379
4393
llvm::errs() << "NewType: " << New->getType().getAsString() << "\n";
0 commit comments