2013-06-13 05:51:50 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wdangling-field -verify -std=c++11 %s
|
2011-09-03 10:21:57 +08:00
|
|
|
|
|
|
|
struct X {
|
|
|
|
X(int);
|
|
|
|
};
|
|
|
|
struct Y {
|
|
|
|
operator X*();
|
|
|
|
operator X&();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
int &x, *y; // expected-note {{reference member declared here}} \
|
|
|
|
// expected-note {{pointer member declared here}}
|
|
|
|
S(int i)
|
|
|
|
: x(i), // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}}
|
|
|
|
y(&i) {} // expected-warning {{initializing pointer member 'y' with the stack address of parameter 'i'}}
|
|
|
|
S(int &i) : x(i), y(&i) {} // no-warning: reference parameter
|
|
|
|
S(int *i) : x(*i), y(i) {} // no-warning: pointer parameter
|
|
|
|
};
|
|
|
|
|
|
|
|
struct S2 {
|
|
|
|
const X &x; // expected-note {{reference member declared here}}
|
Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension."
This change breaks on ARM because pointers to clang::InitializedEntity are only
4 byte aligned and do not have 3 bits to store values. A possible solution
would be to change the fields in clang::InitializedEntity to enforce a bigger
alignment requirement.
The error message is
llvm/include/llvm/ADT/PointerIntPair.h:132:3: error: static_assert failed "PointerIntPair with integer size too large for pointer"
static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
include/llvm/ADT/PointerIntPair.h:73:13: note: in instantiation of template class 'llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> >' requested here
Value = Info::updateInt(Info::updatePointer(0, PtrVal),
llvm/include/llvm/ADT/PointerIntPair.h:51:5: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::setPointerAndInt' requested here
setPointerAndInt(PtrVal, IntVal);
^
llvm/tools/clang/lib/Sema/SemaInit.cpp:6237:12: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::PointerIntPair' requested here
return {Entity, LK_Extended};
Full log here:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/1330
http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/1394
llvm-svn: 337255
2018-07-17 17:23:31 +08:00
|
|
|
S2(int i) : x(i) {} // expected-warning {{binding reference member 'x' to a temporary}}
|
2011-09-03 10:21:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct S3 {
|
|
|
|
X &x1, *x2;
|
|
|
|
S3(Y y) : x1(y), x2(y) {} // no-warning: conversion operator
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T> struct S4 {
|
|
|
|
T x; // expected-note {{reference member declared here}}
|
|
|
|
S4(int i) : x(i) {} // expected-warning {{binding reference member 'x' to stack allocated parameter 'i'}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct S4<int>; // no warning from this instantiation
|
|
|
|
template struct S4<int&>; // expected-note {{in instantiation}}
|
2013-06-13 05:51:50 +08:00
|
|
|
|
|
|
|
struct S5 {
|
|
|
|
const X &x; // expected-note {{here}}
|
|
|
|
};
|
|
|
|
S5 s5 = { 0 }; // ok, lifetime-extended
|
|
|
|
|
|
|
|
struct S6 {
|
|
|
|
S5 s5; // expected-note {{here}}
|
Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension."
This change breaks on ARM because pointers to clang::InitializedEntity are only
4 byte aligned and do not have 3 bits to store values. A possible solution
would be to change the fields in clang::InitializedEntity to enforce a bigger
alignment requirement.
The error message is
llvm/include/llvm/ADT/PointerIntPair.h:132:3: error: static_assert failed "PointerIntPair with integer size too large for pointer"
static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
include/llvm/ADT/PointerIntPair.h:73:13: note: in instantiation of template class 'llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> >' requested here
Value = Info::updateInt(Info::updatePointer(0, PtrVal),
llvm/include/llvm/ADT/PointerIntPair.h:51:5: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::setPointerAndInt' requested here
setPointerAndInt(PtrVal, IntVal);
^
llvm/tools/clang/lib/Sema/SemaInit.cpp:6237:12: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::PointerIntPair' requested here
return {Entity, LK_Extended};
Full log here:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/1330
http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/1394
llvm-svn: 337255
2018-07-17 17:23:31 +08:00
|
|
|
S6() : s5 { 0 } {} // expected-warning {{binding reference subobject of member 's5' to a temporary}}
|
2013-06-13 05:51:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct S7 : S5 {
|
Temporarily revert r337226 "Restructure checking for, and warning on, lifetime extension."
This change breaks on ARM because pointers to clang::InitializedEntity are only
4 byte aligned and do not have 3 bits to store values. A possible solution
would be to change the fields in clang::InitializedEntity to enforce a bigger
alignment requirement.
The error message is
llvm/include/llvm/ADT/PointerIntPair.h:132:3: error: static_assert failed "PointerIntPair with integer size too large for pointer"
static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
include/llvm/ADT/PointerIntPair.h:73:13: note: in instantiation of template class 'llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> >' requested here
Value = Info::updateInt(Info::updatePointer(0, PtrVal),
llvm/include/llvm/ADT/PointerIntPair.h:51:5: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::setPointerAndInt' requested here
setPointerAndInt(PtrVal, IntVal);
^
llvm/tools/clang/lib/Sema/SemaInit.cpp:6237:12: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::PointerIntPair' requested here
return {Entity, LK_Extended};
Full log here:
http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/1330
http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/1394
llvm-svn: 337255
2018-07-17 17:23:31 +08:00
|
|
|
S7() : S5 { 0 } {} // expected-warning {{binding reference member 'x' to a temporary}}
|
2013-06-13 05:51:50 +08:00
|
|
|
};
|