forked from OSchip/llvm-project
Access control for surrogate function calls. Required a moderately gross hack
to get the access bits set properly in conversion sets. llvm-svn: 94744
This commit is contained in:
parent
1051937c21
commit
2cb941642e
|
@ -147,6 +147,10 @@ public:
|
||||||
decls().pop_back();
|
decls().pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setAccess(iterator I, AccessSpecifier AS) {
|
||||||
|
I.ir->setInt(AS);
|
||||||
|
}
|
||||||
|
|
||||||
void clear() { decls().clear(); }
|
void clear() { decls().clear(); }
|
||||||
void set_size(unsigned N) { decls().set_size(N); }
|
void set_size(unsigned N) { decls().set_size(N); }
|
||||||
|
|
||||||
|
|
|
@ -2086,6 +2086,11 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
|
||||||
if (Record->isInvalidDecl())
|
if (Record->isInvalidDecl())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Set access bits correctly on the directly-declared conversions.
|
||||||
|
UnresolvedSetImpl *Convs = Record->getConversionFunctions();
|
||||||
|
for (UnresolvedSetIterator I = Convs->begin(), E = Convs->end(); I != E; ++I)
|
||||||
|
Convs->setAccess(I, (*I)->getAccess());
|
||||||
|
|
||||||
if (!Record->isAbstract()) {
|
if (!Record->isAbstract()) {
|
||||||
// Collect all the pure virtual methods and see if this is an abstract
|
// Collect all the pure virtual methods and see if this is an abstract
|
||||||
// class after all.
|
// class after all.
|
||||||
|
|
|
@ -6231,7 +6231,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
|
||||||
= cast<CXXConversionDecl>(
|
= cast<CXXConversionDecl>(
|
||||||
Best->Conversions[0].UserDefined.ConversionFunction);
|
Best->Conversions[0].UserDefined.ConversionFunction);
|
||||||
|
|
||||||
// FIXME: access control
|
CheckMemberOperatorAccess(LParenLoc, Object, Conv, Best->getAccess());
|
||||||
|
|
||||||
// We selected one of the surrogate functions that converts the
|
// We selected one of the surrogate functions that converts the
|
||||||
// object parameter to a function pointer. Perform the conversion
|
// object parameter to a function pointer. Perform the conversion
|
||||||
|
@ -6246,8 +6246,8 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
|
||||||
CommaLocs, RParenLoc).release();
|
CommaLocs, RParenLoc).release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getLangOptions().AccessControl)
|
CheckMemberOperatorAccess(LParenLoc, Object,
|
||||||
CheckAccess(R, Best->Function, Best->getAccess());
|
Best->Function, Best->getAccess());
|
||||||
|
|
||||||
// We found an overloaded operator(). Build a CXXOperatorCallExpr
|
// We found an overloaded operator(). Build a CXXOperatorCallExpr
|
||||||
// that calls this method, using Object for the implicit object
|
// that calls this method, using Object for the implicit object
|
||||||
|
|
|
@ -39,15 +39,21 @@ namespace test1 {
|
||||||
void operator+(Public&);
|
void operator+(Public&);
|
||||||
void operator[](Public&);
|
void operator[](Public&);
|
||||||
void operator()(Public&);
|
void operator()(Public&);
|
||||||
|
typedef void (*PublicSurrogate)(Public&);
|
||||||
|
operator PublicSurrogate() const;
|
||||||
protected:
|
protected:
|
||||||
void operator+(Protected&); // expected-note {{declared protected here}}
|
void operator+(Protected&); // expected-note {{declared protected here}}
|
||||||
void operator[](Protected&); // expected-note {{declared protected here}}
|
void operator[](Protected&); // expected-note {{declared protected here}}
|
||||||
void operator()(Protected&); // expected-note {{declared protected here}}
|
void operator()(Protected&); // expected-note {{declared protected here}}
|
||||||
|
typedef void (*ProtectedSurrogate)(Protected&);
|
||||||
|
operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
|
||||||
private:
|
private:
|
||||||
void operator+(Private&); // expected-note {{declared private here}}
|
void operator+(Private&); // expected-note {{declared private here}}
|
||||||
void operator[](Private&); // expected-note {{declared private here}}
|
void operator[](Private&); // expected-note {{declared private here}}
|
||||||
void operator()(Private&); // expected-note {{declared private here}}
|
void operator()(Private&); // expected-note {{declared private here}}
|
||||||
void operator-(); // expected-note {{declared private here}}
|
void operator-(); // expected-note {{declared private here}}
|
||||||
|
typedef void (*PrivateSurrogate)(Private&);
|
||||||
|
operator PrivateSurrogate() const; // expected-note {{declared private here}}
|
||||||
};
|
};
|
||||||
void operator+(const A &, Public&);
|
void operator+(const A &, Public&);
|
||||||
void operator+(const A &, Protected&);
|
void operator+(const A &, Protected&);
|
||||||
|
@ -71,5 +77,9 @@ namespace test1 {
|
||||||
ca + prot;
|
ca + prot;
|
||||||
ca + priv;
|
ca + priv;
|
||||||
-ca;
|
-ca;
|
||||||
|
// These are all surrogate calls
|
||||||
|
ca(pub);
|
||||||
|
ca(prot); // expected-error {{access to protected member}}
|
||||||
|
ca(priv); // expected-error {{access to private member}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue