alex
alex

Reputation: 9

Strange code in clang API

I read source code clang API, and seen this code

00127   Optional<T> getAs() const {
00128     if (!T::isKind(*this))
00129       return None;
00130     T t;
00131     ProgramPoint& PP = t;
00132     PP = *this;
00133     return t;
00134   }

what does code on the lines 130-133? For what? http://clang.llvm.org/doxygen/ProgramPoint_8h_source.html#l00127

Upvotes: 1

Views: 94

Answers (1)

Sebastian
Sebastian

Reputation: 1889

130: Create the return value, default initialized.

131: Create a reference to the return value.

132: Assign to the reference, using the assignment operator of ProgramPoint. Didn't find one on first glance, so it's probably using the compiler generated assignment operator.

133: return it

The purpose of creating a reference could be one or more of:

  • Check if T is a subclass of ProgramPoint
  • Force use of the ProgramPoint assignment operator (and not of the subclass T) in line 132

Upvotes: 1

Related Questions