llvm.org GIT mirror llvm / 290ad96
Add unused result attr to the casting templates This helped catch a couple of bugs locally. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199793 91177308-0d34-0410-b5e6-96231b3b80d8 Alp Toker 6 years ago
1 changed file(s) with 12 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_SUPPORT_CASTING_H
1515 #define LLVM_SUPPORT_CASTING_H
1616
17 #include "llvm/Support/Compiler.h"
1718 #include "llvm/Support/type_traits.h"
1819 #include
1920
130131 // if (isa(myVal)) { ... }
131132 //
132133 template
133 inline bool isa(const Y &Val) {
134 LLVM_ATTRIBUTE_UNUSED_RESULT inline bool isa(const Y &Val) {
134135 return isa_impl_wrap
135136 typename simplify_type::SimpleType>::doit(Val);
136137 }
244245 // accepted.
245246 //
246247 template
247 inline typename cast_retty::ret_type cast_or_null(Y *Val) {
248 LLVM_ATTRIBUTE_UNUSED_RESULT inline typename cast_retty::ret_type
249 cast_or_null(Y *Val) {
248250 if (Val == 0) return 0;
249251 assert(isa(Val) && "cast_or_null() argument of incompatible type!");
250252 return cast(Val);
260262 //
261263
262264 template
263 inline typename enable_if_c::value,
264 typename cast_retty::ret_type>::type
265 LLVM_ATTRIBUTE_UNUSED_RESULT inline typename enable_if_c<
266 !is_simple_type::value, typename cast_retty::ret_type>::type
265267 dyn_cast(const Y &Val) {
266268 return isa(Val) ? cast(Val) : 0;
267269 }
268270
269271 template
270 inline typename cast_retty::ret_type dyn_cast(Y &Val) {
272 LLVM_ATTRIBUTE_UNUSED_RESULT inline typename cast_retty::ret_type
273 dyn_cast(Y &Val) {
271274 return isa(Val) ? cast(Val) : 0;
272275 }
273276
274277 template
275 inline typename cast_retty::ret_type dyn_cast(Y *Val) {
278 LLVM_ATTRIBUTE_UNUSED_RESULT inline typename cast_retty::ret_type
279 dyn_cast(Y *Val) {
276280 return isa(Val) ? cast(Val) : 0;
277281 }
278282
280284 // value is accepted.
281285 //
282286 template
283 inline typename cast_retty::ret_type dyn_cast_or_null(Y *Val) {
287 LLVM_ATTRIBUTE_UNUSED_RESULT inline typename cast_retty::ret_type
288 dyn_cast_or_null(Y *Val) {
284289 return (Val && isa(Val)) ? cast(Val) : 0;
285290 }
286291