[llvm-bugs] [Bug 45020] New: -Winvalid-constexpr fails with specialisation when interacting with automatic reference counting
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Feb 25 02:37:23 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=45020
Bug ID: 45020
Summary: -Winvalid-constexpr fails with specialisation when
interacting with automatic reference counting
Product: clang
Version: trunk
Hardware: PC
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: sdefresne at google.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
Specialisation of a template to support "id" (the Objective-C type) uniformly
the same way as pointer to Objective-C object cause failure of "constexpr"
compilation.
Small reproduction case:
=== s.mm
#import <Foundation/Foundation.h>
template<typename T>
struct a {
explicit constexpr a(__unsafe_unretained T o = nil) : o_(o) {}
__unsafe_unretained T o_;
};
template<typename T>
struct b : a<T> {
explicit constexpr b(T __attribute__((ns_consumed)) o = nil) : a<T>(o) {}
};
template<typename T>
struct c : b<T*> {
explicit constexpr c(T* __attribute__((ns_consumed)) o = nil) : b<T*>(o) {}
};
template<>
struct c<id> : b<id> {
explicit constexpr c(id __attribute__((ns_consumed)) o = nil) : b<id>(o) {}
};
void foo() {
b<id> _0([[NSObject alloc] init]);
c<id> _1([[NSObject alloc] init]);
c<NSObject> _2(([[NSObject alloc] init]));
}
===
Compiling this with the following options "--std=c++14 -fobjc-arc" results in
the following error:
s.mm:23:22: error: constexpr constructor never produces a constant expression
[-Winvalid-constexpr]
explicit constexpr c(id __attribute__((ns_consumed)) o = nil) : b<id>(o) {}
^
s.mm:23:73: note: subexpression not valid in a constant expression
explicit constexpr c(id __attribute__((ns_consumed)) o = nil) : b<id>(o) {}
^
I would expect the "constexpr" to fail compilation for all of b<id>, c<id> and
c<NSObject> or for none of them. However, it only fails for c<id> which makes
me think this is a bad interaction between specialisation, ARC (automatic
reference counting) and the annotations.
The following alternative way to specialise via trait does not produce any
error:
===t.mm
#import <Foundation/Foundation.h>
template<typename T>
struct a {
explicit constexpr a(__unsafe_unretained T o = nil) : o_(o) {}
__unsafe_unretained T o_;
};
template<typename T>
struct b : a<T> {
explicit constexpr b(T __attribute__((ns_consumed)) o = nil) : a<T>(o) {}
};
template<typename T>
struct t {
typedef T* tp;
};
template<>
struct t<id> {
typedef id tp;
};
template<typename T>
struct c : b<typename t<T>::tp> {
typedef typename t<T>::tp tp;
explicit constexpr c(tp __attribute__((ns_consumed)) o = nil) : b<tp>(o) {}
};
void foo() {
b<id> _0([[NSObject alloc] init]);
c<id> _1([[NSObject alloc] init]);
c<NSObject> _2(([[NSObject alloc] init]));
}
===
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200225/d15c2cb3/attachment.html>
More information about the llvm-bugs
mailing list