我是一个 OIer
,我会做一些题目,然后在我用 g++
编译我的程序的时候发现了一点问题,然后我本来想注册一个 Bugzilla
账号的,结果没注册成功
这是我编译用的代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod;
struct nd{
int l,r;
LL tag,taggg,val;
}tree[800005];
int n;
LL arr[200005];
int ls(int p){return (p<<1);}
int rs(int p){return ((p<<1)|1);}
void add(int p,LL mul,LL add){
tree[p].val=(tree[p].val*mul+add*(tree[p].r-tree[p].l+1))%mod;
tree[p].tag=(tree[p].tag*mul)%mod;
tree[p].taggg=(tree[p].taggg*mul+add)%mod;
return;
}
void pushdown(int p){
if ((tree[p].tag^1)||tree[p].taggg){
add(ls(p),tree[p].tag,tree[p].taggg);
add(rs(p),tree[p].tag,tree[p].taggg);
tree[p].tag=1;
tree[p].taggg=0;
}
return;
}
void pushup(int p){
tree[p].val=(tree[ls(p)].val+tree[rs(p)].val)%mod;
return;
}
void build(int p,int l,int r){
tree[p]={l,r,1,0,0};
if (l==r){tree[p].val=arr[l];return;}
int mid=(l+r)>>1;
build(ls(p),l,mid);build(rs(p),mid+1,r);
pushup(p);
return;
}
void update(int p,int l,int r,LL val,LL val2){
if (l<=tree[p].l&&tree[p].r<=r){add(p,val,val2);return;}
int mid=(tree[p].l+tree[p].r)>>1;
pushdown(p);
if (l<=mid){update(ls(p),l,r,val,val2);}
if (r>mid){update(rs(p),l,r,val,val2);}
pushup(p);
return;
}
LL query(int p,int l,int r){
if (l>tree[p].r||r<tree[p].l){return 0;}
if (l<=tree[p].l&&tree[p].r<=r){return tree[p].val;}
int mid=(tree[p].l+tree[p].r)>>1;
pushdown(p);
LL res=0;
if (l<=mid){(res+=query(ls(p),l,r))%=mod;}
if (r>mid){(res+=query(rs(p),l,r))%=mod;}
return res;
}
int main(){
int T,l,r;LL x,y;char op;
scanf("%d%lld",&n,&mod);
for (int i=1;i<=n;++i){scanf("%lld",arr+i);arr[i]%=mod;}
build(1,1,n);
scanf("%d",&T);++T;while (--T){
scanf("%hhd%d%d",&op,&l,&r);
if (op^3){scanf("%lld",&x);x%=mod;y=0;if (op&2){swap(x,y);x=1;}update(1,l,r,x,y);continue;}
printf("%lld\n",query(1,l,r));
}
return 0;
}
编译选项:
g++ -m64 -DOFFLINE_JUDGE -lm -O2 -std=c++14 -static -Wall -Wextra -fsanitize=undefined -o main main.cpp -g
main.cpp: In function ‘void pushdown(int)’:
g++-14
输出:
main.cpp:22:37: warning: array subscript -1 is below array bounds of ‘nd [800005]’ [-Warray-bounds=]
22 | add(rs(p),tree[p].tag,tree[p].taggg);
| ~~~~~~^
main.cpp:8:2: note: while referencing ‘tree’
8 | }tree[800005];
| ^~~~
main.cpp:22:25: warning: array subscript -1 is below array bounds of ‘nd [800005]’ [-Warray-bounds=]
22 | add(rs(p),tree[p].tag,tree[p].taggg);
| ~~~~~~^
main.cpp:8:2: note: while referencing ‘tree’
8 | }tree[800005];
g++-11
没有报 warning
g++
版本
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 14.2.0-19' --with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr --with-gcc-major-version-only --program-suffix=-14 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/reproducible-path/gcc-14-14.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/reproducible-path/gcc-14-14.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=3
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Debian 14.2.0-19)
Debian GNU/Linux
版本
lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 13 (trixie)
Release: 13
Codename: trixie
我的问题:
-
g++-14
这里报warning
合不合理 -
要是它报
warning
是对的话,为什么只报了add(rs(p),tree[p].tag,tree[p].taggg);
而没报add(ls(p),tree[p].tag,tree[p].taggg);
-
如果这是一个
Bug
的话,它是Debian
的问题还是GCC
的问题?