我们刚刚在代码库中发现了一个问题,其中一个语句位于return语句之后。
例如
std::string MyClass::addElement(Type1 &item, const std::string ¶m2)
{
if (param2.empty())
{
// logging
return "";
}
return m_database->addElement(item, param2, item.status, true);
// here I would expect an unreachable code warning
m_database->updateTableA(item.p1, item.p2, item.p3, AType::AType23);
}
我不明白,为什么我们的编译器(GCC 4.8.5和7)没有发出警告?
我们使用-std=c++0x -Wall -Wextra -Wsign-compare -Wunknown-pragmas -Wold-style-cast -Wshadow -Wfatal-errors
答案 0 :(得分:4)
GCC 不能针对无效代码发出警告,因为import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import FixedLenFeature
featdef = {
'train/image': FixedLenFeature(shape=[], dtype= tf.string),
'train/label': FixedLenFeature(shape = [], dtype = tf.int64)
}
def _parse_record (example_proto, clip = False):
ex = tf.parse_single_example(example_proto, featdef)
im = tf.decode_raw(ex['train/image'], tf.uint8)
im = tf.reshape(im, (28,28,3))
im = tf.cast(im, tf.float32)*(1./255)
#label = (ex['train/label'])
label = tf.one_hot(ex['train/label'], 2)
print(label)
print(im)
return im, label
batch_size = 50
ds_train = tf.data.TFRecordDataset('/home/mudit/AI/TFrecord_Datasets/Melanoma_training_uint8.tfrecords').map(_parse_record)
ds_train = ds_train.repeat().shuffle(1000).batch(batch_size)
IM_SIZE = 28
image_input = tf.keras.Input(shape = (IM_SIZE, IM_SIZE, 3), name = 'input_layer')
conv_1 = tf.keras.layers.Conv2D(32, kernel_size = (3,3),
padding = 'same',
activation = 'relu')(image_input)
conv1 = tf.keras.layers.MaxPooling2D(padding = 'same')(conv_1)
conv_2 = tf.keras.layers.Conv2D(32, kernel_size = (3,3), padding = 'same',
activation = 'relu')(conv_1)
conv_flat = tf.keras.layers.Flatten()(conv_2)
fc_1 = tf.keras.layers.Dense(28,
activation='relu')(conv_flat)
fc_1 = tf.keras.layers.Dropout(0.2)(fc_1)
fc_2 = tf.keras.layers.Dense(28,
activation='relu')(fc_1)
fc_2 = tf.keras.layers.Dropout(0.4)(fc_2)
label_output = tf.keras.layers.Dense(2,
activation='softmax',
name='label')(fc_2)
model = tf.keras.Model(inputs = image_input, outputs = [label_output])
print(model.summary())
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
history = model.fit(ds_train, steps_per_epoch = 500, epochs = 8)
标志/功能在版本4.4之后已被删除,您可以阅读。
当使用model.fit()
标志编译代码时,Clang版本4(现在的头数是8,所以我不建议这样做)也会发出警告。
警告:代码将永远不会执行[-Wunreachable-code]
您可以尝试使用静态分析工具,其中here中有很多工具。