Skip to content

Commit

Permalink
Forbid assigning to Buffer(Expr) by introducing an intermediate type. (
Browse files Browse the repository at this point in the history
…halide#7517)

* Forbid assigning to Buffer(Expr) by introducing an intermediate type.

Fixes halide#7514

* Simpler solution

* Silence clang-tidy
  • Loading branch information
abadams authored and ardier committed Mar 3, 2024
1 parent c1c597b commit e2dee3a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,19 @@ class Buffer {
}
// @}

/** Make an Expr that loads from this concrete buffer at a computed coordinate. */
/** Make an Expr that loads from this concrete buffer at a computed
* coordinate. Returned Expr is const so that it's not possible to
* accidentally treat a buffer like a Func and try to assign an Expr to a
* given symbolic coordinate. */
// @{
template<typename... Args>
Expr operator()(const Expr &first, Args... rest) const {
const Expr operator()(const Expr &first, Args... rest) const { // NOLINT
std::vector<Expr> args = {first, rest...};
return (*this)(args);
}

template<typename... Args>
Expr operator()(const std::vector<Expr> &args) const {
const Expr operator()(const std::vector<Expr> &args) const { // NOLINT
return buffer_accessor(Buffer<>(*this), args);
}
// @}
Expand Down

0 comments on commit e2dee3a

Please sign in to comment.