r322236 - In C++17, when instantiating an out-of-line definition of an inline static data

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 17 04:58:04 PST 2018


Merged to 6.0 in r322641.

On Thu, Jan 11, 2018 at 12:08 AM, Richard Smith via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: rsmith
> Date: Wed Jan 10 15:08:26 2018
> New Revision: 322236
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322236&view=rev
> Log:
> In C++17, when instantiating an out-of-line definition of an inline static data
> member, don't forget to instantiate the initializer too.
>
> Modified:
>     cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>     cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
>     cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jan 10 15:08:26 2018
> @@ -4151,7 +4151,8 @@ void Sema::BuildVariableInstantiation(
>    // it right away if the type contains 'auto'.
>    if ((!isa<VarTemplateSpecializationDecl>(NewVar) &&
>         !InstantiatingVarTemplate &&
> -       !(OldVar->isInline() && OldVar->isThisDeclarationADefinition())) ||
> +       !(OldVar->isInline() && OldVar->isThisDeclarationADefinition() &&
> +         !NewVar->isThisDeclarationADefinition())) ||
>        NewVar->getType()->isUndeducedType())
>      InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs);
>
>
> Modified: cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/cxx1z-inline-variables.cpp Wed Jan 10 15:08:26 2018
> @@ -58,14 +58,22 @@ template<typename T> struct X {
>    static int a;
>    static inline int b;
>    static int c;
> +  static const int d;
> +  static int e;
>  };
>  // CHECK: @_ZN1XIiE1aE = linkonce_odr global i32 10
>  // CHECK: @_ZN1XIiE1bE = global i32 20
>  // CHECK-NOT: @_ZN1XIiE1cE
> +// CHECK: @_ZN1XIiE1dE = linkonce_odr constant i32 40
> +// CHECK: @_ZN1XIiE1eE = linkonce_odr global i32 50
>  template<> inline int X<int>::a = 10;
>  int &use3 = X<int>::a;
>  template<> int X<int>::b = 20;
>  template<> inline int X<int>::c = 30;
> +template<typename T> constexpr int X<T>::d = 40;
> +template<typename T> inline int X<T>::e = 50;
> +const int *use_x_int_d = &X<int>::d;
> +const int *use_x_int_e = &X<int>::e;
>
>  template<typename T> struct Y;
>  template<> struct Y<int> {
>
> Modified: cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp?rev=322236&r1=322235&r2=322236&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp (original)
> +++ cfe/trunk/test/SemaTemplate/cxx17-inline-variables.cpp Wed Jan 10 15:08:26 2018
> @@ -16,3 +16,14 @@ namespace CompleteType {
>
>    constexpr int n = X<true>::value;
>  }
> +
> +template <typename T> struct A {
> +  static const int n;
> +  static const int m;
> +  constexpr int f() { return n; }
> +  constexpr int g() { return n; }
> +};
> +template <typename T> constexpr int A<T>::n = sizeof(A) + sizeof(T);
> +template <typename T> inline constexpr int A<T>::m = sizeof(A) + sizeof(T);
> +static_assert(A<int>().f() == 5);
> +static_assert(A<int>().g() == 5);
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list