[PATCH] D97965: [clang] Fix crash when creating deduction guide.
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG4e1c487004a2: [clang] Fix crash when creating deduction guide. (authored by adamcz). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97965/new/ https://reviews.llvm.org/D97965 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,17 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. The diagnostic could + // be improved, but the point of this test is to simply check we do not crash. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,17 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. The diagnostic could + // be improved, but the point of this test is to simply check we do not crash. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97965: [clang] Fix crash when creating deduction guide.
adamcz added inline comments. Comment at: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp:425 + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; hokein wrote: > The diagnostic seems bogus, but I think it is at least better than crashing, > I'd add add a FIXME to fix this bogus diagnostic here?. I added a line about improving the diagnostic. I'm a bit hesitant to leave a FIXME, since it doesn't seem like something actually worth spending time on. Just a weird corner case on broken code. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97965/new/ https://reviews.llvm.org/D97965 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97965: [clang] Fix crash when creating deduction guide.
adamcz updated this revision to Diff 329346. adamcz added a comment. expanded a comment Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97965/new/ https://reviews.llvm.org/D97965 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,17 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. The diagnostic could + // be improved, but the point of this test is to simply check we do not crash. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,17 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. The diagnostic could + // be improved, but the point of this test is to simply check we do not crash. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97965: [clang] Fix crash when creating deduction guide.
hokein accepted this revision. hokein added a comment. This revision is now accepted and ready to land. Thanks! Comment at: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp:425 + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; The diagnostic seems bogus, but I think it is at least better than crashing, I'd add add a FIXME to fix this bogus diagnostic here?. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97965/new/ https://reviews.llvm.org/D97965 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97965: [clang] Fix crash when creating deduction guide.
adamcz updated this revision to Diff 328206. adamcz added a comment. format Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97965/new/ https://reviews.llvm.org/D97965 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,16 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,16 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} // namespace no_crash_on_default_arg + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D97965: [clang] Fix crash when creating deduction guide.
adamcz created this revision. adamcz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. We used to trigger assertion when transforming c-tor with unparsed default argument. Now we ignore such constructors for this purpose. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D97965 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,16 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp === --- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -416,6 +416,16 @@ } +namespace no_crash_on_default_arg { +class A { + template class B { +B(int c = 1); + }; + // This used to crash due to unparsed default arg above. + B(); // expected-error {{deduction guide declaration without trailing return type}} +}; +} + #pragma clang diagnostic push #pragma clang diagnostic warning "-Wctad-maybe-unsupported" namespace test_implicit_ctad_warning { Index: clang/lib/Sema/SemaTemplate.cpp === --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -2494,6 +2494,12 @@ if (!CD || (!FTD && CD->isFunctionTemplateSpecialization())) continue; +// Cannot make a deduction guide when unparsed arguments are present. +if (std::any_of(CD->param_begin(), CD->param_end(), [](ParmVarDecl *P) { + return !P || P->hasUnparsedDefaultArg(); +})) + continue; + Transform.transformConstructor(FTD, CD); AddedAny = true; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits